博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OC 自定义导航栏返回按钮宽度自适应
阅读量:6852 次
发布时间:2019-06-26

本文共 1569 字,大约阅读时间需要 5 分钟。

+(UIBarButtonItem *)backButtonWithTitle:(NSString *)title titleColor:(UIColor *)color imageName:(NSString *)imageName target:(id)target action:(SEL)action{        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];        [button setTitleColor:color forState:UIControlStateNormal];    [button setTitle:title forState:UIControlStateNormal];    button.titleLabel.font = [UIFont boldSystemFontOfSize:15];        [button setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];    [button setImage:[[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected", imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateSelected];        button.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);        [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];    paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;//省略方式 ...在后面         NSDictionary *attributes = @{                                 NSParagraphStyleAttributeName : paragraphStyle,                                 };    button.titleLabel.attributedText = [[NSAttributedString alloc] initWithString:title attributes: attributes];        [button sizeToFit];        //100是你想限制的最大宽度    if (button.width > 100)    {        button.width = 100;    }        return [[UIBarButtonItem alloc]initWithCustomView:button];}

 

转载于:https://www.cnblogs.com/joezblog/p/5497336.html

你可能感兴趣的文章
Android Day03-SQLite数据库操作及ListView详解
查看>>
Looking for APAC Operations IT XML Database Developer in Shenzhen and Hongkong
查看>>
Myeclipse常用快捷键
查看>>
我的友情链接
查看>>
Unity3d多线程
查看>>
炉石传说 C# 开发笔记 (源代码整理公开)
查看>>
前端文摘:Web 开发模式演变历史和趋势
查看>>
最大子数组和问题的解
查看>>
cout设置输出数据不显示科学计数法
查看>>
zoj 1659 Mobile Phone Coverage(矩形面积并)
查看>>
python学习 day3
查看>>
Centos 6.4下用Squid配置反向代理多个内网WEB服务器
查看>>
王者荣耀之父姚晓光“奇葩”的工作理念
查看>>
Flask 信号
查看>>
Extjs checkbox数值回显
查看>>
SpringBatch配置数据库
查看>>
SVN使用svn+ssh协议连接服务器时重复提示输入密码 解决办法
查看>>
微信公众平台开发(107) 分享到朋友圈和发送给好友
查看>>
GeoTiff如何存储颜色表的研究
查看>>
HTTP请求GET/POST查看工具
查看>>