如果toolbar直接设置frame为CGRectMake(0, 0, 320,
66)的话,左右两边的按钮会往上跑(按钮水平居中的高度是66),所以可以写下面的代码覆盖状态栏的颜色(不用考虑toolbar左右两边的按钮位置除外)
//覆盖状态栏的颜色
UIView *statusView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 22)];
//创建toolbar
MyToolbar *toolbar = [[MyToolbar alloc]initWithFrame:CGRectMake(0, 22, 320, 44)];
//创建toolbar右边的按钮
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"set"] style:UIBarButtonItemStylePlain target:self action:nil];
//设置按钮颜色
rightItem.tintColor = [UIColor whiteColor];
//创建弹性空白
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
时间: 2025-01-02 18:51:30