@于iOS6之前,需要使用NSMutableAttributedString当你需要导入:CoreText.framework框架的。但在iOS6 之后就不在须要了.

- (void)testOfNSMutableAttributedStringAndNSAttributedString
{
/**
* - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;
* 主要方法
* name 属性名
* value 属性相应效果的值
* range 效果所映射的范围
*/ #pragma mark 測试数据0
NSString *testString = @"NSMutableAttributed---0";
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 100, 200, 40)];
NSMutableAttributedString * testAttriString = [[NSMutableAttributedString alloc] initWithString:testString];
// 加入删除线
[testAttriString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, testAttriString.length)];
// 加入下划线
[testAttriString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, testAttriString.length)];
// 设置文本的字体以及大小
[testAttriString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:15] range:NSMakeRange(0, testAttriString.length)];
// 设置笔画的粗细
[testAttriString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleDouble] range:NSMakeRange(0, testAttriString.length)];
// label的背景颜色
[testAttriString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, testAttriString.length)];
// 眼下没測出什么效果.....
[testAttriString addAttribute:NSVerticalGlyphFormAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(0, testAttriString.length)];
// label上文本颜色(也会影响删除线和下划线的颜色)
[testAttriString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, testAttriString.length)];
testLabel.attributedText = testAttriString; #pragma mark 測试数据1
NSString *testString1 = @"NSMutableAttributed---1";
UILabel *testLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 200, 200, 40)];
NSMutableAttributedString * testAttriString1 = [[NSMutableAttributedString alloc] initWithString:testString1];
// 实现文本内容颜色和下划线,删除线的颜色不一样
// NSStrokeColorAttributeName 单独设置没有效果
// 必须与NSStrokeWidthAttributeName一起设置
[testAttriString1 addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, testAttriString1.length)];
[testAttriString1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, testAttriString1.length)];
[testAttriString1 addAttribute:NSStrokeColorAttributeName value:[UIColor cyanColor] range:NSMakeRange(0, testAttriString1.length)];
[testAttriString1 addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleDouble] range:NSMakeRange(0, testAttriString1.length)];
testLabel1.attributedText = testAttriString1; #pragma mark 測试数据2
NSString *testString2 = @"NSMutableAttributed---2";
UILabel *testLabel2= [[UILabel alloc] initWithFrame:CGRectMake(60, 300, 200, 40)];
NSMutableAttributedString * testAttriString2 = [[NSMutableAttributedString alloc] initWithString:testString2];
// 笔画的阴影效果
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[UIColor colorWithRed:0.053 green:0.088 blue:0.205 alpha:1.000]];
[shadow setShadowBlurRadius:4.0];
[shadow setShadowOffset:CGSizeMake(2, 2)];
[testAttriString2 addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, [testAttriString2 length])];
testLabel2.backgroundColor = [UIColor clearColor];
testLabel2.attributedText = testAttriString2; [self.view addSubview:testLabel];
[self.view addSubview:testLabel1];
[self.view addSubview:testLabel2];
}
使用AttributedString的方式通常有两种:

方式一:

    首先初始化一个NSMutableAttributedString。然后向里面加入文字样式,最后将它赋给控件的AttributedText,该方法适合于文本较少而又须要分段精细控制的情况。

NSString *originStr = @"Hello,中秋节。";

//方式一

//创建 NSMutableAttributedString
NSMutableAttributedString *attributedStr01 = [[NSMutableAttributedString alloc] initWithString: originStr]; //加入属性 //给全部字符设置字体为Zapfino,字体高度为15像素
[attributedStr01 addAttribute: NSFontAttributeName value: [UIFont fontWithName: @"Zapfino" size: 15]
range: NSMakeRange(0, originStr.length)];
//分段控制,最開始4个字符颜色设置成蓝色
[attributedStr01 addAttribute: NSForegroundColorAttributeName value: [UIColor blueColor] range: NSMakeRange(0, 4)];
//分段控制。第5个字符開始的3个字符。即第5、6、7字符设置为红色
[attributedStr01 addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange(4, 3)]; //赋值给显示控件label01的 attributedText
_label01.attributedText = attributedStr01; 方式二: 首先创建属性字典,初始化各种属性。然后和须要控制的文本一起创建并赋值给控件的AttributedText,该方法适合于须要控制的文本较多总体控制的情况,一般是从文件里读取的大段文本控制。 //方式二 //创建属性字典
NSDictionary *attrDict = @{ NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15],
NSForegroundColorAttributeName: [UIColor blueColor] }; //创建 NSAttributedString 并赋值
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict]; 通过对照两个样例能够看出。方式一比較easy处理复杂的格式。可是属性设置比較繁多复杂,而方式二的属性设置比較简单明了,却不善于处理复杂多样的格式控制,可是不善于并不等于不能。能够通过属性字符串分段的方式来达到方式一的效果。例如以下: //方式二的分段处理
//第一段
NSDictionary *attrDict1 = @{ NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15],
NSForegroundColorAttributeName: [UIColor blueColor] };
NSAttributedString *attrStr1 = [[NSAttributedString alloc] initWithString: [originStr substringWithRange: NSMakeRange(0, 4)] attributes: attrDict1]; //第二段
NSDictionary *attrDict2 = @{ NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15],
NSForegroundColorAttributeName: [UIColor redColor] };
NSAttributedString *attrStr2 = [[NSAttributedString alloc] initWithString: [originStr substringWithRange: NSMakeRange(4, 3)] attributes: attrDict2]; //第三段
NSDictionary *attrDict3 = @{ NSFontAttributeName: [UIFont fontWithName: @"Zapfino" size: 15],
NSForegroundColorAttributeName: [UIColor blackColor] };
NSAttributedString *attrStr3 = [[NSAttributedString alloc] initWithString: [originStr substringWithRange:
NSMakeRange(7, originStr.length - 4 - 3)] attributes: attrDict3];
//合并
NSMutableAttributedString *attributedStr03 = [[NSMutableAttributedString alloc] initWithAttributedString: attrStr1];
[attributedStr03 appendAttributedString: attrStr2];
[attributedStr03 appendAttributedString: attrStr3]; _label03.attributedText = attributedStr03; @AttributedString到底能够设置哪些属性,详细来说。有以下21个:
// NSFontAttributeName 设置字体属性,默认值:字体:Helvetica(Neue) 字号:12
// NSForegroundColorAttributeNam 设置字体颜色,取值为 UIColor对象,默认值为黑色
// NSBackgroundColorAttributeName 设置字体所在区域背景颜色。取值为 UIColor对象,默认值为nil, 透明色
// NSLigatureAttributeName 设置连体属性,取值为NSNumber 对象(整数)。0 表示没有连体字符,1 表示使用默认的连体字符
// NSKernAttributeName 设定字符间距,取值为 NSNumber 对象(整数)。正值间距加宽,负值间距变窄
// NSStrikethroughStyleAttributeName 设置删除线,取值为 NSNumber 对象(整数)
// NSStrikethroughColorAttributeName 设置删除线颜色。取值为 UIColor 对象,默认值为黑色
// NSUnderlineStyleAttributeName 设置下划线,取值为 NSNumber 对象(整数)。枚举常量 NSUnderlineStyle中的值,与删除线相似
// NSUnderlineColorAttributeName 设置下划线颜色,取值为 UIColor 对象,默认值为黑色
// NSStrokeWidthAttributeName 设置笔画宽度,取值为 NSNumber 对象(整数)。负值填充效果,正值中空效果
// NSStrokeColorAttributeName 填充部分颜色。不是字体颜色,取值为 UIColor 对象
// NSShadowAttributeName 设置阴影属性,取值为 NSShadow 对象
// NSTextEffectAttributeName 设置文本特殊效果,取值为 NSString 对象,眼下仅仅有图版印刷效果可用:
// NSBaselineOffsetAttributeName 设置基线偏移值,取值为 NSNumber (float),正值上偏。负值下偏
// NSObliquenessAttributeName 设置字形倾斜度,取值为 NSNumber (float),正值右倾。负值左倾
// NSExpansionAttributeName 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
// NSWritingDirectionAttributeName 设置文字书写方向,从左向右书写或者从右向左书写
// NSVerticalGlyphFormAttributeName 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
// NSLinkAttributeName 设置链接属性,点击后调用浏览器打开指定URL地址
// NSAttachmentAttributeName 设置文本附件,取值为NSTextAttachment对象,经常使用于文字图片混排
// NSParagraphStyleAttributeName 设置文本段落排版格式,取值为 NSParagraphStyle 对象  以下就一一举例说明: 1. NSFontAttributeName //NSForegroundColorAttributeName 设置字体颜色,取值为 UIColor,默觉得黑色 NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };
NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 注意: NSForegroundColorAttributeName设置的颜色与UILabel的textColor属性设置的颜色在地位上是相等的。谁最后赋值。终于显示的就是谁的颜色。 2. NSBackgroundColorAttributeName //NSForegroundColorAttributeName 设置字体颜色。取值为 UIColor。默觉得黑色 NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };
NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; //NSBackgroundColorAttributeName 设置字体所在区域背景的颜色,取值为UIColor。默认值为nil NSDictionary *attrDict4 = @{ NSBackgroundColorAttributeName: [UIColor orangeColor] };
NSDictionary *attrDict5 = @{ NSBackgroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict6 = @{ NSBackgroundColorAttributeName: [UIColor cyanColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict4];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict5];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict6]; 细致观察会发现个问题。我并没有关闭 NSForegroundColorAttributeName 属性,可是在执行结果中,全部字体的颜色都变成了默认色——黑色。这说明 NSForegroundColorAttributeName 和 NSBackgroundColorAttributeName 的低位是相等的,跟前面介绍的 textColor 一样。哪个属性最后一次赋值。就会冲掉前面的效果,若是我们把属性代码顺序交换一下 //NSBackgroundColorAttributeName 设置字体所在区域背景的颜色,取值为UIColor。默认值为nil NSDictionary *attrDict4 = @{ NSBackgroundColorAttributeName: [UIColor orangeColor] };
NSDictionary *attrDict5 = @{ NSBackgroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict6 = @{ NSBackgroundColorAttributeName: [UIColor cyanColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict4];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict5];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict6]; //NSForegroundColorAttributeName 设置字体颜色,取值为 UIColor,默觉得黑色 NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };
NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 可是textColor属性能够与 NSBackgroundColorAttributeName 属性叠加 _label01.textColor = [UIColor greenColor];
_label02.textColor = [UIColor yellowColor];
_label03.textColor = [UIColor blueColor]; //NSForegroundColorAttributeName 设置字体颜色,取值为 UIColor,默觉得黑色 NSDictionary *attrDict1 = @{ NSForegroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict2 = @{ NSForegroundColorAttributeName: [UIColor blueColor] };
NSDictionary *attrDict3 = @{ NSForegroundColorAttributeName: [UIColor orangeColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; //NSBackgroundColorAttributeName 设置字体所在区域背景的颜色,取值为UIColor。默认值为nil NSDictionary *attrDict4 = @{ NSBackgroundColorAttributeName: [UIColor orangeColor] };
NSDictionary *attrDict5 = @{ NSBackgroundColorAttributeName: [UIColor redColor] };
NSDictionary *attrDict6 = @{ NSBackgroundColorAttributeName: [UIColor cyanColor] }; _label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict4];
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict5];
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict6]; 尽管 textColor 在 NSFontAttributeName 之前赋值,可是因为 NSFontAttributeName 的属性效果被NSBackgroundColorAttributeName 属性冲掉了。所以终于显示了 textColor 的颜色。 3. NSLigatureAttributeName //NSLigatureAttributeName 设置连体属性,取值为NSNumber 对象(整数)。0 表示没有连体字符。1 表示使用默认的连体字符,
// 2 表示使用全部连体符号,默认值为 1(iOS 不支持 2) NSString *ligatureStr = @"flush"; NSDictionary *attrDict1 = @{ NSLigatureAttributeName: [NSNumber numberWithInt: 0],
NSFontAttributeName: [UIFont fontWithName: @"futura" size: 30] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: ligatureStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSLigatureAttributeName: @(1),
NSFontAttributeName: [UIFont fontWithName: @"futura" size: 30]
};
_label02.attributedText = [[NSAttributedString alloc] initWithString: ligatureStr attributes: attrDict2];
因为要展示连体字符。所以将前面使用的带有中文的字符串换成 flush NSLigatureAttributeName的取值为NSNumber对象,所以不能直接将一个整数值赋给它,创建 NSNumber 对象的方法有非常多,或者能够简写成 @(int) 注意观察字母f和l之间的变化。 感觉连写就是一个艺术字功能,当字符f和l组合使用组合符号(所谓的字形(glyph))绘制时,看起来确实更加美观。可是并不是全部的字符之间都有组合符号。其实,仅仅有某些字体中得某些字符的组合(如字符f和l。字符f和i等)才具有美观的组合符号。 4. NSKernAttributeName //NSKernAttributeName 设定字符间距,取值为 NSNumber 对象(整数),正值间距加宽。负值间距变窄 NSDictionary *attrDict1 = @{ NSKernAttributeName: @(-3),
NSFontAttributeName: [UIFont systemFontOfSize: 20]
};
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSKernAttributeName: @(0),
NSFontAttributeName: [UIFont systemFontOfSize: 20]
};
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSKernAttributeName: @(10),
NSFontAttributeName: [UIFont systemFontOfSize: 20]
};
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 5. NSStrikethroughStyleAttributeName //NSStrikethroughStyleAttributeName 设置删除线。取值为 NSNumber 对象(整数)。枚举常量 NSUnderlineStyle中的值
// NSUnderlineStyleNone 不设置删除线
// NSUnderlineStyleSingle 设置删除线为细单实线
// NSUnderlineStyleThick 设置删除线为粗单实线
// NSUnderlineStyleDouble 设置删除线为细双实线 NSDictionary *attrDict1 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSStrikethroughStyleAttributeName: @(NSUnderlineStyleDouble),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];
注意: 尽管使用了枚举常量,可是枚举常量的本质仍为整数。所以相同必须先转化为 NSNumber 才干使用 删除线和下划线使用相同的枚举常量作为其属性值 眼下iOS中仅仅有上面列出的4中效果,尽管我们能够在头文件里发现其它很多其它的取值。可是使用后没有不论什么效果 能够看出,中文和英文删除线的位置有所不同 另外。删除线属性取值除了上面的4种外,其实还能够取其它整数值,有兴趣的能够自行试验,取值为 0 - 7时,效果为单实线,随着值得添加,单实线逐渐变粗。取值为 9 - 15时。效果为双实线。取值越大,双实线越粗。 NSDictionary *attrDict1 = @{ NSStrikethroughStyleAttributeName: @(1),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSStrikethroughStyleAttributeName: @(3),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSStrikethroughStyleAttributeName: @(7),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 6. NSStrikethroughColorAttributeName //NSStrikethroughColorAttributeName 设置删除线颜色,取值为 UIColor 对象,默认值为黑色 NSDictionary *attrDict1 = @{ NSStrikethroughColorAttributeName: [UIColor blueColor],
NSStrikethroughStyleAttributeName: @(1),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSStrikethroughColorAttributeName: [UIColor orangeColor],
NSStrikethroughStyleAttributeName: @(3),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSStrikethroughColorAttributeName: [UIColor greenColor],
NSStrikethroughStyleAttributeName: @(7),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 7. NSUnderlineStyleAttributeName 下划线除了线条位置和删除线不同外,其它的都能够全然參照删除线设置。 //NSUnderlineStyleAttributeName 设置下划线,取值为 NSNumber 对象(整数)。枚举常量 NSUnderlineStyle中的值,与删除线相似 NSDictionary *attrDict1 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleThick),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSUnderlineStyleAttributeName: @(NSUnderlineStyleDouble),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 8. NSUnderlineColorAttributeName 能够全然參照下划线颜色设置 //NSUnderlineColorAttributeName 设置下划线颜色,取值为 UIColor 对象。默认值为黑色 NSDictionary *attrDict1 = @{ NSUnderlineColorAttributeName: [UIColor blueColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSUnderlineColorAttributeName: [UIColor orangeColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleThick),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSUnderlineColorAttributeName: [UIColor greenColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleDouble),
NSFontAttributeName: [UIFont systemFontOfSize:20] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 9. NSStrokeWidthAttributeName //NSStrokeWidthAttributeName 设置笔画宽度,取值为 NSNumber 对象(整数)。负值填充效果,正值中空效果 NSDictionary *attrDict1 = @{ NSStrokeWidthAttributeName: @(-3),
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSStrokeWidthAttributeName: @(0),
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSStrokeWidthAttributeName: @(3),
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3]; 10. NSStrokeColorAttributeName //NSStrokeColorAttributeName 填充部分颜色,不是字体颜色,取值为 UIColor 对象 NSDictionary *attrDict1 = @{ NSStrokeWidthAttributeName: @(-3),
NSStrokeColorAttributeName: [UIColor orangeColor],
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label01.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict1]; NSDictionary *attrDict2 = @{ NSStrokeWidthAttributeName: @(0),
NSStrokeColorAttributeName: [UIColor blueColor],
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label02.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict2]; NSDictionary *attrDict3 = @{ NSStrokeWidthAttributeName: @(3),
NSStrokeColorAttributeName: [UIColor greenColor],
NSFontAttributeName: [UIFont systemFontOfSize:30] };
_label03.attributedText = [[NSAttributedString alloc] initWithString: originStr attributes: attrDict3];

版权声明:本文博主原创文章,博客,未经同意不得转载。

iOS6之后 NSAttributedString 福利的更多相关文章

  1. iOS6、7、8、9新特性汇总和适配说明

    iOS6新特性 一.关于内存警告 ios6中废除了viewDidUnload,viewWillUnload这两个系统回调,收到内存警告时在didReceiveMemoryWarning中进行相关的处理 ...

  2. NSAttributedString的用法

    标签: 以前看到这种字号和颜色不一样的字符串,想出个讨巧的办法就是“¥150”一个UILable,“元/位”一个UILable.今天翻看以前的工程,command点进UITextField中看到[at ...

  3. IOS6 字体高亮显示

    ios6之前在一个字符串中如果也让某个字体高亮或者特殊显示(如: 关注[ ]),需要用单独一个的标签进行显示,或者利用CoreText进行字体绘绘制,非常麻烦: 现在IOS6 中TextView,la ...

  4. iOS6 以上设置文本高度,行高(转)

    2013-12-09     我来说两句   来源:冻僵的企鹅'zone   收藏    我要投稿 在iOS 7之前,常用下面这个方法计算文本高度sizeWithFont:constrainedToS ...

  5. NSAttributedString用法

    以前看到这种字号和颜色不一样的字符串,想出个讨巧的办法就是“¥150”一个UILabel,“元/位”一个UILabel.今天翻看以前的工程,command点进UITextField中看到[attrib ...

  6. IOS6新特性之下拉刷新<UIRefreshControl>

    在IOS6未发布之前,几乎都是使用那个UIRefresh在实现下拉刷新,甚至有人还是先了上拉的功能,不得不说牛人很多啊.可能是Apple意识到了这个功能的实用性,在IOS6中增加了下拉刷新,但是上啦还 ...

  7. 适用于iOS6之后的苹果提供的下拉刷新

    一:iOS6.0及以后: 下拉刷新控件UIRefreshControl TableView属性:refreshControl 二:使用 - (void)colseTheTB { [self dismi ...

  8. ios NSAttributedString 具体解释

    ios NSAttributedString 具体解释 NSAttributedString能够让我们使一个字符串显示的多样化,可是眼下到iOS 5为止,好像对它支持的不是非常好,由于显示起来不太方便 ...

  9. IOS6 新特性之UIRefreshControl

    "不会模仿的公司不是好公司不会剽窃的公司不是优秀公司  不会调戏代码的不是骨灰级码工 你同意吗? 苹果估计想取代第三方的pull to refresh"        ------ ...

随机推荐

  1. Android编程心得-图片自适应心得

    在Android 的开发过程中,我们知道存放图片资源的文件夹是drawable,与它类似的名字的文件夹drawble-hdpi,drawable-ldpi,drawable-mdpi,drawable ...

  2. Java集群--大型网站是怎样解决多用户高并发访问的

    时间过得真快,再次登录博客园来写博,才发现距离上次的写博时间已经过去了一个月了,虽然是因为自己找了实习,但这也说明自己对时间的掌控能力还是没那么的强,哈哈,看来还需不断的努力啊!(这里得特别说明一下本 ...

  3. android各种资源的详细解释

    1.字符数组      使用字符串数组资源<string-array>标签定义,在<string-array>包括一些标签<item>数组元素标记.   例如 &l ...

  4. 游戏开发实验室的内部讲座总结----c++

     第三节  动态内存分配new和delete 经过调试设置断点,发现new 函数事实上还是调用的malloc函数. 第四节  引用 一个变量是能够有多个引用的,引用也是能够传递的.  常量是不能有 ...

  5. 【翻译】Why JavaScript Is and Will Continue to Be the First Choice of Programmers

    花费2半小时,那么最终会被翻译.假设有问题,请提出,毕竟,自己的6不超过级别. 附加链接 Why JavaScript Is and Will Continue to Be the First Cho ...

  6. UML序列图总结(转)

    序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色用一条虚线 ...

  7. VirtualBox安装ubuntu14.04和文件共享

    因为机器的VMware使用很卡,占用更多的内存,所以我想,以取代VirtualBox.已安装ubuntu14.04使用与VMware在相同的. VirtualBox下载链接:https://www.v ...

  8. Ubuntu下超实用的命令

    1. Ubuntu中查看已安装软件包的方法 sudodpkg -l 2. ubuntu系统如何查看软件安装的位置 dpkg-L软件名 实例: wwx@ubuntu:~$dpkg -L mysql-se ...

  9. VB6.0“挑衅”.NET!

    来到与两年前接触VB,现在学习VB.NET,这两个看起来真的不得不说,这是相对的似(ps:一分之差,只有三个字母),计等.但他们有又什么不同呢?都说VB.NET高级,比VB究竟高级在哪里了?是不是VB ...

  10. VMware vSphere 服务器虚拟化之十八桌面虚拟化之安装View Composer服务器

                        VMware vSphere 服务器虚拟化之十八桌面虚拟化之安装View Composer服务器      View Compose服务可安装在管理虚拟机的vC ...