ios富文本属性
2016-05-16 09:09
405 查看
@interface
ViewController ()@property
(weak,nonatomic)
IBOutlet
UILabel
*stringLabel;@end@implementation
ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
NSString
*string = _stringLabel.text;
//初始化属性字符串
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
//字体类型属性
NSDictionary
*BoldFontAS = @{NSFontAttributeName:[UIFont
boldSystemFontOfSize:17]};
[attributedString addAttributes:BoldFontAS range:[string rangeOfString:@"BoldFont"]];
//字体颜色属性
NSDictionary
*RedFondAS = @{NSForegroundColorAttributeName :[UIColor
redColor]};
[attributedString addAttributes:RedFondAS range:[string rangeOfString:@"RedFont"]];
//字体背景颜色和字体颜色属性
NSDictionary
*BuleBackgroundAS = @{NSBackgroundColorAttributeName:[UIColor
blueColor], NSForegroundColorAttributeName:[UIColor
whiteColor]};
[attributedString addAttributes:BuleBackgroundAS range:[string rangeOfString:@"BuleBackground"]];
//字体下划线与字体下划线颜色属性
NSDictionary
*UnderlineAS = @{NSUnderlineStyleAttributeName:[NSNumber
numberWithInteger:NSUnderlineStyleSingle],NSUnderlineColorAttributeName:[UIColor
greenColor]};
[attributedString addAttributes:UnderlineAS range:[string rangeOfString:@"Underline"]];
//字体阴影属性
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset
= CGSizeMake(2,
2);
shadow.shadowColor
= [UIColor
orangeColor];
NSDictionary
*ShadowAS = @{NSShadowAttributeName:shadow};
[attributedString addAttributes:ShadowAS range:[string rangeOfString:@"Shadow"]];
//设置Label的字符串属性
_stringLabel.attributedText
= attributedString;}
ViewController ()@property
(weak,nonatomic)
IBOutlet
UILabel
*stringLabel;@end@implementation
ViewController
- (void)viewDidLoad
{
[super
viewDidLoad];
NSString
*string = _stringLabel.text;
//初始化属性字符串
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
//字体类型属性
NSDictionary
*BoldFontAS = @{NSFontAttributeName:[UIFont
boldSystemFontOfSize:17]};
[attributedString addAttributes:BoldFontAS range:[string rangeOfString:@"BoldFont"]];
//字体颜色属性
NSDictionary
*RedFondAS = @{NSForegroundColorAttributeName :[UIColor
redColor]};
[attributedString addAttributes:RedFondAS range:[string rangeOfString:@"RedFont"]];
//字体背景颜色和字体颜色属性
NSDictionary
*BuleBackgroundAS = @{NSBackgroundColorAttributeName:[UIColor
blueColor], NSForegroundColorAttributeName:[UIColor
whiteColor]};
[attributedString addAttributes:BuleBackgroundAS range:[string rangeOfString:@"BuleBackground"]];
//字体下划线与字体下划线颜色属性
NSDictionary
*UnderlineAS = @{NSUnderlineStyleAttributeName:[NSNumber
numberWithInteger:NSUnderlineStyleSingle],NSUnderlineColorAttributeName:[UIColor
greenColor]};
[attributedString addAttributes:UnderlineAS range:[string rangeOfString:@"Underline"]];
//字体阴影属性
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset
= CGSizeMake(2,
2);
shadow.shadowColor
= [UIColor
orangeColor];
NSDictionary
*ShadowAS = @{NSShadowAttributeName:shadow};
[attributedString addAttributes:ShadowAS range:[string rangeOfString:@"Shadow"]];
//设置Label的字符串属性
_stringLabel.attributedText
= attributedString;}
相关文章推荐
- 一些ios牛人的博客
- 开发IOS推送功能客户端需要做的事情
- iOS开发之沙盒机制
- iOS离线打包
- Tutorial: iOS Reverse Engineering Part II: class-dump & Hopper
- IOS tableview 横向滚动
- iOS雷达图 iOS RadarChart实现
- iOS的查询、过滤(NSPredicate)
- iOS图片不失真拉伸方法
- iOS中的正则表达式
- OC Unicode和汉字(utf8)的互转
- iOS截取正方形的图片
- iOS获取请求连接的cookies
- Tutorial: iOS Reverse Engineering Part I: LLDB
- 滑动手势
- iOS中的定位
- iOS开发装逼特技之 实用快捷键系列
- iOS中利用 runtime 一键改变字体
- iOS发开蛋疼集锦
- ios记录-数据存储