brandonscript
brandonscript

Reputation: 72915

What is the Swift equivalent of [UIColor colorWithWhite:alpha]

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?

Upvotes: 4

Views: 2934

Answers (2)

mariusLAN
mariusLAN

Reputation: 1205

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)

Upvotes: 9

Pradeep K
Pradeep K

Reputation: 3661

UIColor(white: 0.7, alpha: 1.0)

Upvotes: 2

Related Questions