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换行同时修改字体大小颜色的更多相关文章

  1. 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...

  2. 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)

    typealias PopPickerViewCallBackClosure = (_ resultStr:NSString?) -> () class PopPickerView : UIVi ...

  3. UISegmentedControl 修改字体大小 和 颜色

    UISegmentedControl 修改字体大小 和 颜色 大小: UIFont *font = [UIFont boldSystemFontOfSize:14.0f]; NSDictionary ...

  4. 第一章:eclipse 中修改字体大小和编码格式

    eclipse 中修改字体大小的步骤: 1. 在 eclipse 的工具栏中,找到 weindows 下面的 preferences 2. 在 preferences 的 输出 font ,在 Bas ...

  5. centos7 终端修改字体大小

    如果你觉得你的终端字体太小了,停下来看一看这里可以帮你快捷修改字体大小 修改字体大小(这个是最坑爹的) 其实关键的命令就一个:setfont 但是setfont后面要跟的字体到底要写什么就的具体去查了 ...

  6. Eclipse 在线汉化的和修改字体大小、颜色的方法

    一.在线汉化 先进入 http://www.eclipse.org/babel/downloads.php 找到自己对应版本的网址,然后复制下来. 然后,进入eclipse.点工具栏上的Help - ...

  7. eclipse-ee修改字体大小和配置Tomcat服务器

    参考博客:http://blog.csdn.net/lpftobetheone/article/details/17783791 一.EclipseEE背景色和字体的修改 1.Eclipse背景颜色修 ...

  8. Android spinner默认样式不支持换行和修改字体样式的解决方法

    在spinner中显示的数据过多,需要换行,而Android自身提供的android.R.layout.simple_spinner_dropdown_item样式不支持换行,因此参考android提 ...

  9. Android Studio修改字体大小

    android studio提供的主题是不能修改字体和字体大小的,如果要修改大小就的另存一份自定义的主题了. 1.启动Android Studio,菜单"File"-"S ...

随机推荐

  1. Window Phone 8手电筒

    一直想开发一个Wp8的手电筒程序,看了好多别人开发的基本上有以下问题: 1.锁屏闪光灯关闭了 2.闪光灯不停的闪烁. 我就想开发一个锁屏也能用的手电筒,发现找资料那是相当的困难.找到的代码基本都不能令 ...

  2. Absolute(绝对定位)与relative(相对定位)的图文讲解

    Position的属性值有:1.     Absolute:绝对定位,是相对于最近的且不是static定位的父元素来定位 2.     Fixed:绝对定位,是相对于浏览器窗口来定位的,是固定的,不会 ...

  3. 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 ...

  4. iOS第三方地图-高德地图(导航sdk路径规划)

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  5. Python2.6.6升级2.7.3

    Python2.7替换2.6: 1.下载Python-2.7.3 #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 2.解压 ...

  6. BZOJ 3527 [Zjoi2014]力 ——FFT

    [题目分析] FFT,构造数列进行卷积,挺裸的一道题目诶. 还是写起来并不顺手,再练. [代码] #include <cmath> #include <cstdio> #inc ...

  7. 刷题总结——奇怪的游戏(scoi2012)

    题目: 题目描述 Blinker 最近喜欢上一个奇怪的游戏.这个游戏在一个 N*M  的棋盘上玩,每个格子有一个数.每次 Blinker  会选择两个相邻的格子,并使这两个数都加上 1.现在 Blin ...

  8. 虚拟机vmnet0、vmnet1和vmnet8的区别 虚拟网卡概述

    vmnet0,实际上就是一个虚拟的网桥 vmnet0,实际上就是一个虚拟的网桥,这个网桥有很若干个端口,一个端口用于连接你的Host,一个端口用于连接你的虚拟机,他们的位置是对等的,谁也不是谁的网关. ...

  9. 金鹰dreamweaver视频教程下载地址

    原文发布时间为:2008-07-30 -- 来源于本人的百度文章 [由搬家工具导入] http://download2.gbaopan.com/c188aecb5e524ab2b2a484c061e0 ...

  10. Java面试题集(二)

    51.设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1,写出程序.  以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题. public class ThreadTest1 ...