【发布时间】:2014-04-01 19:30:06
【问题描述】:
在我的应用程序中,我有一个 UItextView,它的输入视图有附件视图,上面有几个按钮。
我正在尝试将已输入的文本更改为下划线文本。它工作正常,但在转换后会丢失字体和字体大小。
这就是我正在做的事情:
NSRange selectedRange = [self.commentsTextView selectedRange];
NSDictionary *currentAttributesDict = [self.commentsTextView.textStorage attributesAtIndex:selectedRange.location
effectiveRange:nil];
NSDictionary *dict;
if ([currentAttributesDict objectForKey:NSUnderlineStyleAttributeName] == nil ||
[[currentAttributesDict objectForKey:NSUnderlineStyleAttributeName] intValue] == 0) {
dict = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInt:1]};
}
else{
dict = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInt:0]};
}
[self.commentsTextView.textStorage beginEditing];
[self.commentsTextView.textStorage setAttributes:dict range:selectedRange];
[self.commentsTextView.textStorage endEditing];
【问题讨论】:
标签: ios objective-c textkit