iOS如何修改UIBarButtonItem的间距

参考代码:主要设置创建一个UIBarButtonSystemItemFixedSpace样式的UIBarButtonItem,然后设置间距,代码如下:

UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];

searchBtn.frame = CGRectMake(0,0,21, 21);

//[searchBtn setTitle:@"搜索" forState:UIControlStateNormal];

[searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];

[searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateHighlighted];

searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];

[searchBtn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];

UIBarButtonItem *rightSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

rightSpace.width = -7;

self.navigationItem.rightBarButtonItems = @[rightSpace,rightItem];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 838评论 0 0
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,547评论 1 14
  • 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现cl...
    以德扶人阅读 2,466评论 2 50
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 3,721评论 2 7
  • 1.transform属性 在OC中,通过transform属性可以修改对象的平移、缩放比例和旋转角度 常用的创建...
    SacredBillows阅读 1,380评论 0 0