How to highlight text like in the image?

前端 未结 4 551

How to highlight the text \"cell phone\" in the image?

\"enter

Updated

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 16:43

    Use NSMutableAttributedString this might work for you.

    NSString *myString = @"Hello";
    NSMutableAttributedString *aString = [[NSMutableAttributedString alloc] initWithString:myString];
    NSRange theRange = NSMakeRange(0,[aString length]);
    

    //Here we are setting foreground and background color to text for highlighting it.

    [aString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"MyriadPro-Bold" size:17.5f] range:theRange];
    [aString addAttribute:NSForegroundColorAttributeName value:[UIColor purpleColor] range:theRange];
    [aString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:theRange];
    

    //You can change the range depending upon what portion of text you want to highlight.

提交回复
热议问题