iOS UILabel换行同时修改字体大小颜色

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #3e1e81 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; min-height: 16.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #d12f1b }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #703daa }
span.s1 { color: #000000 }
span.s2 { color: #703daa }
span.s3 { }
span.s4 { color: #4f8187 }
span.s5 { color: #31595d }
span.s6 { color: #d12f1b }
span.s7 { color: #272ad8 }
span.s8 { color: #ba2da2 }
span.s9 { color: #3e1e81 }
span.s10 { color: #78492a }
span.s11 { font: 14.0px "PingFang SC" }
span.s12 { color: #008400 }
span.s13 { font: 14.0px "PingFang SC"; color: #008400 }

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];

效果图

时间: 2024-08-18 10:12:29

iOS UILabel换行同时修改字体大小颜色的相关文章

AttributedString - 富文本(不同字体大小颜色,下划线中划线)

1 #import "ViewController.h" 2 3 @interface ViewController () 4 5 @end 6 7 @implementation ViewController 8 9 - (void)viewDidLoad { 10 [super viewDidLoad]; 11 // Do any additional setup after loading the view, typically from a nib. 12 13 NSArray

【转】 iOS 在UILabel显示不同的字体和颜色

原文: http://my.oschina.net/CarlHuang/blog/138363 iOS UILabel NSAttributedText NSMutableAttributedText Objective-C 在项目开发中,我们经常会遇到在这样一种情形:在一个UILabel 使用不同的颜色或不同的字体来体现字符串,在iOS 6 以后我们可以很轻松的实现这一点,官方的API 为我们提供了UILabel类的attributedText, 使用不同颜色和不同字体的字符串,我们可以使用N

Eclipse修改字体、颜色、编译器背景颜色等操作方法

1.eclipse 背景色设置:Window->Preferences->General->Editors->Text Editors->Backgroud colors取消System default 设置成:RGB(204,232,207). 2.字体大小设置:java 字体:菜单windows>Prefenrence>General Appearance>Colors and Fonts 在右边的菜单中选Java> Java Editor Tex

弹框(AlertDialog)和提示信息Toast字体大小颜色设置

一.AlertDialog: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("温馨提示"); builder.setMessage("是否进行下一个病人?"); builder.setPositiveButton("是", new DialogInterface.OnClickListener() { @Override

Eclipse如何修改字体大小

打开Eclipse,找到菜单栏Window - Preferences 在打开的窗口左侧,找到General-Appearance-Colors and Fonts 在窗口的右侧,就可以对具体的某一个语言设置,这里以Java语言为例,展开Java,选中"Java Editor Text Font",点击右侧的"Edit"按钮 在打开的字体设置页面,即可对字体大小和样式进行设置,设置完成后,点击确定保存就可以了.

Android-修改TabWidget字体大小颜色及对齐

在Android中,我们可以定义TabWidget来分页.在上一篇文章中有说到使用TabWidget定义Tab分页布局,但大部分用户可能会觉得默认的字体有点小,但Tab选项卡默认又不能设定字体大小,如果我们想要自定义样式,怎么办呢? 可以参考下面的定义方式来控制TabWidget中的标题样式:  //(重要:设定Taps的标题的字体大小.对齐方式等) for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { //获取标题

latex: font size 修改字体大小的几种方式

参考:Adjusting font size with TikZ picture 调整字体大小的几种方式,大小依次增大,具体如下: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge 用法如下: \node (c) at (1,2) {\large x}; 版权声明:本文为博主原创文章,未经博主允许不得转载.

LaTeX :font size 修改字体大小的几种方式

调整字体大小的几种方式,大小依次增大,具体如下: \tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge [Reference] 1.Adjusting font size with TikZ picture 原文地址:https://www.cnblogs.com/shenxiaolin/p/10316436.html

C# 修改字体大小 样式的一些基础知识

txtName 是Textbox文本框 1 单纯修改字体    txtName.Font = new Font("仿宋", txtName.Font.Size, txtName.Font.Style); 2 单纯修改字体样式    txtName.Font = new Font(txtName.Font, txtName.Font.Style | FontStyle.Bold); (在原有样式中加)  ^(与是本来有该种样式的变为没有); 3 初始话字体         txtName