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

kTTTBackgroundFillColorAttributeName代わりにキーを使用する必要があります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 に答える