HomeiOS Developmentios - NSAttributedString: The right way to mimic opacity or alpha equal...

ios – NSAttributedString: The right way to mimic opacity or alpha equal utilizing colour


I’m utilizing NSAttributedString for a button title and would really like to have the ability to “gray out” or decrease the alpha or capability of sure textual content. NSAttributedString doesn’t seem to assist you to modify the opacity or alpha worth of the textual content however does allow you to alter the colour utilizing:

NSMutableAttributedString *textual content = 
 [[NSMutableAttributedString alloc] 
   initWithAttributedString: label.attributedText];
[text addAttribute:NSForegroundColorAttributeName 
             value:[UIColor redColor] 
             vary:NSMakeRange(10, 1)];

or:

let vary = (mainString as NSString).vary(of: stringToColor)
let mutableAttributedString = NSMutableAttributedString.init(string: mainString)
mutableAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, worth: UIColor.purple, vary: vary)

On this case, the beginning colour is System Blue. Is there any system that may enable me to change the system colour to the equal of an alpha worth (or opacity) of 0.5?

Thanks for any recommendations.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments