Changing Background color on NSAttributedString
I think you want NSBackgroundColorAttributeName. Such as:
[mutableAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:selectedRange];
For Swift:
attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(0, tillLocation))
Helpful link - Different way to attribute a string