【发布时间】:2012-10-01 18:39:30
【问题描述】:
我试图让用户能够将他们将键入的文本设置为下划线,而无需当前选择文本。这适用于 iOS 6 应用程序,在 UITextView 中输入文本。它将被保存为 NSAttributedString。粗体和斜体工作正常。下划线的某些东西使它无法正常工作。
UITextView *textView = [self noteTextView];
NSMutableDictionary *typingAttributes = [[textView typingAttributes] mutableCopy];
[typingAttributes setObject:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
NSLog(@"attributes after: %@", typingAttributes);
[textView setTypingAttributes:typingAttributes];
NSLog(@"text view attributes after: %@", [textView typingAttributes]);
我的初始日志语句表明它设置为下划线:
attributes after: {
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICFFont: 0xa9c5e30> font-family: \"Verdana\"; font-weight: normal; font-style: normal; font-size: 17px";
NSKern = 0;
NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSStrokeWidth = 0;
NSUnderline = 1;
}
但是紧随其后的日志语句没有显示 nsunderline 属性。删除 textView setTypingAttributes 行没有任何影响。
text view attributes after: {
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICFFont: 0xa9c5e30> font-family: \"Verdana\"; font-weight: normal; font-style: normal; font-size: 17px";
NSKern = 0;
NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSStrokeWidth = 0;
}
我很困惑为什么我让它为粗体和斜体工作,而不是下划线。还有为什么它似乎最初获得属性,然后忘记它。请分享您可能有的任何见解。谢谢。
【问题讨论】:
-
尝试使用系统字体。不确定是下划线还是字体中的字形。
-
有完全相同的问题,它保留了我尝试过的所有属性,除了下划线(我尝试过字体、背景色、前景色、文本对齐等,它们都可以正常工作)。您找到解决方法了吗?
标签: ios ios6 nsattributedstring underline