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 ...
随机推荐
- python ConfigParser 学习
[安装] ConfigParser 是解析配置文件的第三方库,需要安装 pip install ConfigParser [介绍] ConfigParser 是用来读取配置文件(可以是.conf, ...
- [BZOJ3339] Rmq Problem(线段树)
传送门 这个题的方法好像很多啊 1.莫队暴力 2.线段树 + 离线处理 先预处理出sg[i]表示前i个数的sg值,next[i]表示i的下一位置在哪里,如果后面再没有i,那么next[i] = n + ...
- 算法复习——无源汇可行流(zoj2314)
题目: The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nucl ...
- VBA Split()函数
Split()函数返回一个数组,其中包含基于分隔符分割的特定数量的值. 语法 Split(expression[,delimiter[,count[,compare]]]) 参数说明 Expressi ...
- 启动uwsgi报错error while loading shared libraries: libpcre.so.1:
启动uwsgi时候报错: [root@ richie]# /usr/bin/uwsgi --ini /usr/local/nginx/conf/uwsgi.ini /usr/bin/uwsgi: er ...
- Redis常见配置redis.conf
redis的配置文件.相信学过SSH或SSM的读者都知道,配置文件的使用在当下开发已十分普遍,希望大家要熟悉习惯这 种开发方式,废话不多说,来开始我们今天的内容吧. 首先得找到 redis 的配置文件 ...
- bzoj1975: [Sdoi2010]魔法猪学院【k短路&A*算法】
1975: [Sdoi2010]魔法猪学院 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2446 Solved: 770[Submit][Statu ...
- Explosion at Cafebazaar
Explosion at Cafebazaar 时间限制: 1 Sec 内存限制: 128 MB 题目描述 You are an engineer at Cafebazaar and your sp ...
- ajax 分页(jquery分页插件pagination) 小例1
<link rel="stylesheet" href="/plugins/jQuery/page/pagination.css"/> <sc ...
- (45)C#网络3 socket
一.TCP传输 using System.Net.Sockets; 1.最基本客户端连服务器 服务端运行后一直处于监听状态,客户端每启动一次服务端就接收一次连接并打印客户端的ip地址和端口号.(服务端 ...