Displaying NSMutableAttributedString on iOS 8

后端 未结 3 1949
忘掉有多难
忘掉有多难 2021-01-01 21:39

Seems on iOS 8.0 (12A365) NSMutableAttributedString sometimes will not be displayed correctly. The problem obviously occurs when the range of the attribute does

3条回答
  •  孤城傲影
    2021-01-01 22:30

    Try this, first apply an extra NSBackgroundColorAttributeName in whole of the label with a transparent color

    text = [[NSMutableAttributedString alloc] initWithString:@"Green is green. (-> Bug)"];
    [text addAttribute:NSBackgroundColorAttributeName value:[UIColor clearColor] range:(NSRange){0,text.length}]; //Fix
    [text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:(NSRange){9,5}];
    cell.label.attributedText=text
    

提交回复
热议问题