使用NSMutableAttributedString为UIButton/UILabel 快速设置文字的大小,字体,颜色
2016-05-27 00:14
501 查看
<p class="p1"><span class="s1">@property</span><span class="s2"> (</span><span class="s1">weak</span><span class="s2">, </span><span class="s1">nonatomic</span><span class="s2">) </span><span class="s1">IBOutlet</span><span class="s2"> </span><span class="s3">UIButton</span><span class="s2"> *loginbutton;</span></p><p class="p1"><span class="s1">@property</span><span class="s2"> (</span><span class="s1">weak</span><span class="s2">, </span><span class="s1">nonatomic</span><span class="s2">) </span><span class="s1">IBOutlet</span><span class="s2"> </span><span class="s3">UILabel</span><span class="s2"> *lable;</span></p>
</pre><pre name="code" class="objc">
//** 用富文本快速设置Label的文字:字体,大小,颜色 NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init]; // 可以通过ps 设置 行距,间距,对齐方式,拆行方式 [ps setAlignment:NSTextAlignmentCenter]; NSDictionary *attribs = @{ NSFontAttributeName: [UIFont fontWithName:@"Verdana" size:50], NSForegroundColorAttributeName:[UIColor redColor],NSParagraphStyleAttributeName:ps}; NSMutableAttributedString *attributedText =[[NSMutableAttributedString alloc] initWithString:self.lable.text attributes:attribs]; self.lable.attributedText = attributedText;
</pre><pre name="code" class="objc"> //** 用富文本快速设置UIbutton Title的文字:字体,大小,颜色 NSMutableAttributedString *attributedTextForButton =[[NSMutableAttributedString alloc] initWithString:self.loginbutton.titleLabel.text attributes:attribs]; [self.loginbutton setAttributedTitle:attributedTextForButton forState:UIControlStateNormal];
相关文章推荐
- 前台jason 和后台@Requestbody不匹配
- PyQt5:计算器UI(1)
- 介绍KeyTool GUI工具2款
- [工具]iOS UIDatePicker日历选择控件
- JMS Request/Reply Example
- How should I implement request response with JMS?
- UIImageBlur一个image的分类
- Android酷炫实用的开源框架(UI框架)
- Android组件及UI框架大全
- ffmeg thread_queue_size描述
- iOS之UIView动画
- Android中ListView嵌套GridView的简单消息流UI(解决宽高问题)
- UVa 11039 Building designing (贪心+排序+模拟)
- ACM等算法比赛中JAVA 常用"STL"总结:TreeMap,Queue,PriorityQueue等
- UILable的使用,文本高度的计算boundingRectWithSize
- UIView的使用
- ios 获取UIImage图片的像素尺寸
- 手机适配----资源适配篇(values)
- LeetCode-300.Longest Increasing Subsequence
- 字节打印流PrintStream,字符打印流PrintWriter,序列流SequenceInputStream、