前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >缩小自定义导航栏按钮之间的距离 修改导航栏按钮图片的颜色不用系统的颜色

缩小自定义导航栏按钮之间的距离 修改导航栏按钮图片的颜色不用系统的颜色

原创
作者头像
conanma
修改2021-05-11 14:38:11
1.8K0
修改2021-05-11 14:38:11
举报
文章被收录于专栏:正则正则

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

btn.frame= CGRectMake(0, 0, 40, 44);  

[btn addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];  

UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:btn];  

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

/**

width为负数时,相当于btn向右移动width数值个像素,由于按钮本身和  边界间距为5pix,所以width设为-5时,间距正好调整为0;width为正数 时,正好相反,相当于往左移动width数值个像素

*/

negativeSpacer.width = -5;   

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];

千万不要设置tintcolor

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.frame= CGRectMake(0, 0, 30, 44);

    [btn setImage:[[UIImage imageNamed:@"search"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *itemRight = [[UIBarButtonItem alloc] initWithCustomView:btn];

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

    negativeSpacer.width = -10;

self.navigationItem.rightBarButtonItems = @[negativeSpacer,itemRight];

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档