Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

uicolor

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?

like image 516
brandonscript Avatar asked Dec 19 '22 20:12

brandonscript


2 Answers

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)

like image 103
mariusLAN Avatar answered Mar 14 '23 19:03

mariusLAN


UIColor(white: 0.7, alpha: 1.0)

like image 42
Pradeep K Avatar answered Mar 14 '23 19:03

Pradeep K