在一个UILabel的文字采用不同的字体样式和字体大小
2015-12-30 10:19
513 查看
//标题:红包大厅
UILabel* tmp_title=[[UILabel alloc] initWithFrame:CGRectMake(0 , 5, max_View.frame.size.width, 24)];
tmp_title.text=@"进入红包大厅";
[tmp_title setFont:[UIFont boldSystemFontOfSize:22]];
[tmp_title setTextColor:[UIColor redColor]];
[tmp_title setTextAlignment:NSTextAlignmentCenter];
[self addSubview:tmp_title];
//------------
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"进入红包大厅"];
NSRange range1=NSMakeRange(0, 6);
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:10.0] range:NSMakeRange(0, 1)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14.0] range:NSMakeRange(1, 1)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:18.0] range:NSMakeRange(2, 1)];
tmp_title.attributedText=str;
//显示结果如下图:
这是在同一个UILabel 中显示不同的字体大小,还是比较实用的
UILabel* tmp_title=[[UILabel alloc] initWithFrame:CGRectMake(0 , 5, max_View.frame.size.width, 24)];
tmp_title.text=@"进入红包大厅";
[tmp_title setFont:[UIFont boldSystemFontOfSize:22]];
[tmp_title setTextColor:[UIColor redColor]];
[tmp_title setTextAlignment:NSTextAlignmentCenter];
[self addSubview:tmp_title];
//------------
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"进入红包大厅"];
NSRange range1=NSMakeRange(0, 6);
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range1];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:10.0] range:NSMakeRange(0, 1)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14.0] range:NSMakeRange(1, 1)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:18.0] range:NSMakeRange(2, 1)];
tmp_title.attributedText=str;
//显示结果如下图:
这是在同一个UILabel 中显示不同的字体大小,还是比较实用的
相关文章推荐
- UISwitch详解
- beginUpdates和endUpdates-实现UITableView的动画块
- MiniUI——TreeGrid懒加载
- easyui中 在子tabs中 添加新的tabs
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI
- vue.js学习
- EasyUI datagrid detailview
- The project was not built since its build path is incomplete.
- UIStepper详解
- codeforces 612C Replace To Make Regular Bracket Sequence
- IOS---使用代码创建UIButton
- 为OLED屏增加GUI支持5:图片控件
- Interface Builder一些使用技巧
- js动态控制table为easyUI中的DataGrid样式
- iOS Assertion failure in -[UITableView _classicHeightForRowAtIndexPath:]
- iOS 用UIScrollView,UIPageControl制作轮播图
- 最全的UIAlertController的使用
- LeetCode - Unique Paths II
- LeetCode - Unique Paths
- requirejs实验001.对我来说,用AMD的方式来组织代码并不轻松.