Extending iOS 13 UIColor

iOS 13 comes with a new color scheme, and to access the old system colors, you will need to reach for UIColor and maybe create a Color object, like so:

let ourColor = Color(UIColor.systemGray5)

Extending the UIColor class is made easy by switch extension.

extension UIColor {
    var asColor: Color {
        return Color(self)
    }
}

Use it like so:

let ourColor = UIColor.systemGray5.asColor
Jun 2nd, 2020 • Posted in Apple, iOS, Swift, SwiftUI
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>