NavigationItem

创建系统样式的UIBarButtonItem

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:nil];

[item setTintColor:[UIColor redColor]]; 设置item文字或图片的镂空颜色 

创建标题样式的UIBarButtonItem

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"短信" style:UIBarButtonItemStyleDone target:self action:nil];
    
item.enabled = NO; 设置item的点击是否可用

创建图标样式的UIBarButtonItem

UIImage *image = [[UIImage imageNamed:@"iconfont-duanxin"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];  // 32x32 显示原色(粉色)
    
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:nil];

创建自定义样式的UIBarButtonItem

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    
UIBarButtonItem *item  = [[UIBarButtonItem alloc] initWithCustomView:button];

多个UIBarButtonItem添加到LeftBarButtonItems中

[self.navigationItem setLeftBarButtonItems:@[leftItem1, leftItem2, leftItem3]];

一个UIBarButtonItem添加到RightBarButtonItem中

[self.navigationItem setRightBarButtonItem:rightItem];

GT
0 声望0 粉丝