iOS 开发之给UILabel 或者 UIButton标题加下划线
2017-04-26 17:59
363 查看
在开发的过程中,为了提醒用户我们经常会在label或者 button的文字下面添加下划线! cocoa给提供了一个NSString的子类
NSMutableAttributedString,他可以对字符串进行自定义编辑, 比如某个范围内字符串的字体的颜色,大小,当然还可以加下划线, 而UIButton 提供了 - (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state
接口
UIlabel 提供了@property(nullable, nonatomic,copy) NSAttributedString *attributedText;
固给Button添加下划线代码如下:
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"点击查看协议"];
NSRange strRange = {0,[str length]};
[str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
[_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal];
NSMutableAttributedString,他可以对字符串进行自定义编辑, 比如某个范围内字符串的字体的颜色,大小,当然还可以加下划线, 而UIButton 提供了 - (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state
接口
UIlabel 提供了@property(nullable, nonatomic,copy) NSAttributedString *attributedText;
固给Button添加下划线代码如下:
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"点击查看协议"];
NSRange strRange = {0,[str length]};
[str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
[_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal];
相关文章推荐
- IOS 开发之UILabel 或者 UIButton加下划线链接
- 给UILabel 或者 UIButton标题加下划线
- iOS开发:关于UILabel、UIButton、UITextField文字下划线的设置方法(涉及到富文本的知识)
- iOS开发-UILabel和UIButton添加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- IOS UIButton UILabel 等title 添加下划线 swift 版
- IOS开发-代码创建UI控件并修改控件属性(代码创建UIButton、UILabel)
- iOS开发:常用的UIView控件——UILabel、UITextField、UIButton【转】
- iOS开发:常用的UIView控件——UILabel、UITextField、UIButton
- iOS 开发学习之 User Interface(3)iOS 坐标系和 UILabel 与 UIButton
- 给UILabel 或者 UIButton标题加下划线
- IOS开发UI系列之常用控件 UILabel, UITextField, UIButton, UIImageView等常用属性与方法
- iOS开发:真机或者模拟器中,APP中的按钮文字下面自动出现下划线的问题的解决
- iOS开发——基本控件(UIButton,UILabel,UITextField,UISwitch,UISlider,UISegmentedControl)
- iOS开发之 UILabel,UIButton