1

无法弄清楚如何设置范围的背景颜色以使其看起来像荧光笔

下面的黄色不显示为背景色

NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName, (id) NSBackgroundColorAttributeName, nil];
NSArray *objects = [[NSArray alloc] initWithObjects:[UIColor redColor],[NSNumber numberWithInt:kCTUnderlineStyleNone], [UIColor yellowColor], nil];
NSDictionary *linkAttributes = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];

self.madLibLabel.linkAttributes = linkAttributes;


[self.madLibLabel addLinkToURL:[NSURL URLWithString:@"what://"] withRange:[self.madLibLabel.text rangeOfString:@"WHAT"]];
4

1 回答 1

1

您应该改用kTTTBackgroundFillColorAttributeNamekey NSBackgroundColorAttributeName

这是代码片段:

NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName, (id) kTTTBackgroundFillColorAttributeName, nil];
NSArray *objects = [[NSArray alloc] initWithObjects:[UIColor redColor],[NSNumber numberWithInt:kCTUnderlineStyleNone], [UIColor yellowColor], nil];
NSDictionary *linkAttributes = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];

self.madLibLabel.linkAttributes = linkAttributes;


[self.madLibLabel addLinkToURL:[NSURL URLWithString:@"what://"] withRange:[self.madLibLabel.text rangeOfString:@"WHAT"]];
于 2014-11-05T10:01:50.740 回答