Jam*_*son 11 iphone xcode objective-c uitextview ios
如何在文本中加下划线UITextView
.我明白我需要创建一个子类UITextView
,但是会发生什么drawRect:
?
谢谢.
iDe*_*Dev 23
尝试使用NSAttributedString
如下并设置UITextView
.这适用于iOS6.
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Some String"];
[attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName
value:[NSNumber numberWithInt:kCTUnderlineStyleSingle]
range:(NSRange){0,[attString length]}];
Run Code Online (Sandbox Code Playgroud)
有关NSAttributedString
检查的更多信息,请参阅如何使用NSAttributedString?
例如: -
textView.attributedText = attString;
Run Code Online (Sandbox Code Playgroud)
在iOS 6及更高版本中,此类通过使用attributedText属性支持多种文本样式.(早期版本的iOS不支持样式文本.)为此属性设置值会导致文本视图使用属性字符串中提供的样式信息.您仍然可以使用font,textColor和textAlignment属性来设置样式属性,但这些属性适用于文本视图中的所有文本.
文本视图显示的样式文本.
@property(nonatomic,copy) NSAttributedString *attributedText
Run Code Online (Sandbox Code Playgroud)
讨论:默认情况下,此属性为零.为此属性分配新值也会使用相同的字符串数据替换text属性的值,尽管没有任何格式信息.此外,指定新值可更新font,textColor和textAlignment属性中的值,以便它们反映从属性字符串中的位置0开始的样式信息.
如果您想避免包含CoreText,可以使用具有此属性的属性字符串:
@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26109 次 |
最近记录: |