iOS UILabel换行同时修改字体大小颜色
UIButton *onlyPriceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
onlyPriceBtn.layer.borderColor = [HuConfigration uiColorFromString:@"#F0493D"].CGColor;;
onlyPriceBtn.layer.borderWidth = 0.5f;
onlyPriceBtn.layer.cornerRadius = 4;
onlyPriceBtn.layer.masksToBounds = YES;
onlyPriceBtn.frame = CGRectMake(15, CGRectGetMaxY(titleLabel.frame)+15, HHBWIDTH - 30, 60);
[self.bgView addSubview:onlyPriceBtn];
UILabel *btnTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 60)];
btnTitleLabel.center = onlyPriceBtn.center;
btnTitleLabel.textColor = kHuColor(#A5A5A5);
btnTitleLabel.font = [UIFont customFontSize:12];
btnTitleLabel.numberOfLines = 0;
btnTitleLabel.text = @"独享价30.0元\n购买后仅供自己观看学习";//使用斜杠一定不要忘记写numberOfLines 否则无效
btnTitleLabel.textAlignment = NSTextAlignmentCenter;
NSMutableAttributedString *attributer = [[NSMutableAttributedString alloc]initWithString:btnTitleLabel.text];
[attributer addAttribute:NSForegroundColorAttributeName
value:kHuColor(#F0493D)
range:NSMakeRange(0, 8)];
[attributer addAttribute:NSFontAttributeName
value:[UIFont customFontSize:16]
range:NSMakeRange(0, 8)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];//调整行间距
[paragraphStyle setLineSpacing:4];
[attributer addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, btnTitleLabel.text.length)];
[paragraphStyle setAlignment:NSTextAlignmentCenter];//为了美观调整行间距,但是当调整行间距时上面设置的居中不能用看 所以要加这一句 [paragraphStyle setAlignment:NSTextAlignmentCenter] 不然没有居中效果
btnTitleLabel.attributedText = attributer;
[self.bgView addSubview:btnTitleLabel];
效果图

iOS UILabel换行同时修改字体大小颜色的更多相关文章
- 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...
- 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)
typealias PopPickerViewCallBackClosure = (_ resultStr:NSString?) -> () class PopPickerView : UIVi ...
- UISegmentedControl 修改字体大小 和 颜色
UISegmentedControl 修改字体大小 和 颜色 大小: UIFont *font = [UIFont boldSystemFontOfSize:14.0f]; NSDictionary ...
- 第一章:eclipse 中修改字体大小和编码格式
eclipse 中修改字体大小的步骤: 1. 在 eclipse 的工具栏中,找到 weindows 下面的 preferences 2. 在 preferences 的 输出 font ,在 Bas ...
- centos7 终端修改字体大小
如果你觉得你的终端字体太小了,停下来看一看这里可以帮你快捷修改字体大小 修改字体大小(这个是最坑爹的) 其实关键的命令就一个:setfont 但是setfont后面要跟的字体到底要写什么就的具体去查了 ...
- Eclipse 在线汉化的和修改字体大小、颜色的方法
一.在线汉化 先进入 http://www.eclipse.org/babel/downloads.php 找到自己对应版本的网址,然后复制下来. 然后,进入eclipse.点工具栏上的Help - ...
- eclipse-ee修改字体大小和配置Tomcat服务器
参考博客:http://blog.csdn.net/lpftobetheone/article/details/17783791 一.EclipseEE背景色和字体的修改 1.Eclipse背景颜色修 ...
- Android spinner默认样式不支持换行和修改字体样式的解决方法
在spinner中显示的数据过多,需要换行,而Android自身提供的android.R.layout.simple_spinner_dropdown_item样式不支持换行,因此参考android提 ...
- Android Studio修改字体大小
android studio提供的主题是不能修改字体和字体大小的,如果要修改大小就的另存一份自定义的主题了. 1.启动Android Studio,菜单"File"-"S ...
随机推荐
- rocketmq 问题
1. 收不到消息-consumerOffset.json 信息错位 这种情况一般是,手动删除了store/commitlog目录里的数据等非常规手段造成了consumerOffset.json中记录的 ...
- 84. Spring Boot集成MongoDB【从零开始学Spring Boot】
至于MongoDB网上有很多相关的资料,所以在这里不进行过多的介绍,我们在这里主要是介绍下如何将mongodb与spring boot结合使用.本节大纲: (1) 准备工作: (2) 新建一个mave ...
- poj 3617Best Cow Line
Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year&quo ...
- (转)iOS字体
一.iOS原生字体展示 在 label中选择字体的font,并把font由system改成custom后,就能在family中看到72种特殊字体.这些里面就有很炫的字体,但 是全部是只针对英文数字,对 ...
- Codeforces #765D
我在这道题上花了2个小时,仍没解出.理一下当时的思路,看看症结到底在哪里. 题意 用 $[n]$ 表示集合 $\{1,2,3,\dots, n\}$ . 3个函数 $f \colon [n] \to ...
- SPOJ GSS4 Can you answer these queries IV ——树状数组 并查集
[题目分析] 区间开方+区间求和. 由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可. 这不是BZOJ上上帝造题7分钟嘛 [代码] #include < ...
- VMware虚拟机CentOS7 - VMnet8网络配置及常见问题解决
本文环境 物理机OS: Windows10 专业版 虚拟机平台: VMware Workstation 14 虚拟机OS: CentOS 7 配置步骤 一. 查看物理主机的网络配置信息 主要是找到可以 ...
- 标准C程序设计七---17
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- centos 7 配置多个IP地址
centos 7 配置多个IP地址 #打开网络配置文件 cd /etc/sysconfig/network-scripts/ vim ifcfg-eno167 找到IPADDR的位置,在下面再增加需要 ...
- ci框架——辅助函数
辅助函数:application/helper下面.命名要求为***_helper.php;这样在调用的时候直接$this->load->helper('***');若想给自定义的辅助函数 ...