为了账号安全,请及时绑定邮箱和手机立即绑定

UIBarButtonItem有颜色吗?

UIBarButtonItem有颜色吗?

小怪兽爱吃肉 2019-10-24 15:21:31
是否有红色的UIBarButtonItem?
查看完整描述

3 回答

?
白衣染霜花

TA贡献1796条经验 获得超10个赞

如果有人在寻找代码来完全复制一个简单的UIBarButtonItem:


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];

[button setTitle:@"Delete" forState:UIControlStateNormal];

button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];

[button.layer setCornerRadius:4.0f];

[button.layer setMasksToBounds:YES];

[button.layer setBorderWidth:1.0f];

[button.layer setBorderColor: [[UIColor grayColor] CGColor]];

button.frame=CGRectMake(0.0, 100.0, 60.0, 30.0);

[button addTarget:self action:@selector(batchDelete) forControlEvents:UIControlEventTouchUpInside];


UIBarButtonItem* deleteItem = [[UIBarButtonItem alloc] initWithCustomView:button];

和delete.png是:

//img1.sycdn.imooc.com//5db151ae0001259f01130082.jpg

查看完整回答
反对 回复 2019-10-24
?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

您可以使用所需的外观创建自定义UIButton,并将其初始化为自定义视图的UIBarButtonItem。


UIButton *button = [UIButton buttonWithType:....];

...(customize your button)...


UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];


查看完整回答
反对 回复 2019-10-24
  • 3 回答
  • 0 关注
  • 688 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信