4

This in Objective-C returns the default iOS disabled gray color:

[UIColor colorWithWhite: 0.70 alpha:1];

There doesn't appear to be any native Swift function:

UIColor.colorWithWhite(0.70, alpha: 1)

I'm wondering if there's a different way that UIColor has implemented this in Swift that I'm not aware of? I can't seem to find anything in the docs. If not, then what would be an appropriate extension for this method?

0

2 Answers 2

9

In Swift it's all about readability and most of the static methods calls known from Objective-C are dropped now.

[UIColor colorWithWhite:alpha] is now UIColor(white: CGFloat, alpha: CGFloat)

2
  • Yep, that's it! Nice. Might want to re-word your answer though, looks more like a comment ;) Commented Jan 25, 2016 at 7:04
  • Yeah I will do it as soon I am at my workplace desk :)
    – mariusLAN
    Commented Jan 25, 2016 at 7:05
2

UIColor(white: 0.7, alpha: 1.0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.