【发布时间】:2014-04-03 20:27:40
【问题描述】:
请参阅下面的编辑#1,它比原始问题更好地隔离了问题
我正在尝试让 linkTextAttributes 为 UITextView 工作并且对此感到非常沮丧 - 这可能是一个直接的 Obj-C 问题。我宁愿不去 NSAttribtedString 但可能不得不去。我只是想删除链接上的下划线。这有效:
textview.linkTextAttributes = @{NSForegroundColorAttributeName : [UIColor yellowColor]};
要让它变黄,但我需要取出下属。看起来应该是这样的:
textview.linkTextAttributes = @{NSForegroundColorAttributeName : [UIColor yellowColor],
NSUnderlineStyleAttributeName: NSUnderlineStyleNone};
但我得到以下有点神秘的错误:
我试过了:
textview.linkTextAttributes = @{
NSForegroundColorAttributeName : [UIColor yellowColor],
NSUnderlineStyleAttributeName: [NSNumber numberWithInt: NSUnderlineStyleNone]};
删除错误但不删除下划线。关于如何解决这个问题的任何想法?或者上面的语法是否正确?
编辑#1
所以我试图将问题更多地隔离到一个新项目中。这是来自主 UIViewController 的 viewDidLoad;只是试图删除下划线:
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textview= [[UITextView alloc]initWithFrame:CGRectMake(50.0F, 50.0F , 200.0f, 100.0f)];
[textview setValue:@"here is my thinking <a href='http://www.some.com'>me</a>" forKey:@"contentToHTMLString"];
textview.layer.borderWidth = 5.0f;
textview.layer.borderColor = [[UIColor grayColor] CGColor];
textview.dataDetectorTypes = UIDataDetectorTypeLink;
textview.linkTextAttributes = @{
NSForegroundColorAttributeName : [UIColor blueColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)};
[self.view addSubview:textview];
}
和输出:
【问题讨论】:
标签: ios ios7 nsstring nsattributedstring