-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSString+AttributedString.m
More file actions
41 lines (26 loc) · 1.08 KB
/
NSString+AttributedString.m
File metadata and controls
41 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// NSString+AttributedString.m
// DTEN
//
// Created by 东途 on 16/6/13.
// Copyright © 2016年 displayten. All rights reserved.
//
#import "NSString+AttributedString.h"
#import <CoreText/CoreText.h>
@implementation NSString (AttributedString)
+ (NSMutableAttributedString *)attributedString:(NSString *)str fontSize:(int)fontSize color:(UIColor *)color underLine:(NSNumber *)underline {
NSRange range = NSMakeRange(0, str.length);
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:fontSize]
range:range];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:color
range:range];
if (underline > 0) {
// NSUnderlineStyleSingle
[AttributedStr addAttribute:NSUnderlineStyleAttributeName value:underline range:range];
}
return AttributedStr;
}
@end