Cannot extend UIColor

Viewed 29

I tried the steps below to expeand UIColor, but it didn't work.

At first, I added new color set in xcassets, enter image description here

and then add UIColor + Extension.swift in my project folder.

// UIColor + Extension.swift

import Foundation
import UIKit

extension UIColor {

    class var testColor1:UIColor {
      return UIColor(red: 210.0/255.0, green: 105.0/255.0, blue: 130.0/255.0, alpha: 1.0)
    }
    class var testColor2: UIColor? { return UIColor(named: "testColor") }

}

I want to load custom color in AppDelegate.mm, but got the following error. enter image description here

animationUIView.backgroundColor = [UIColor testColor1];

The code above doesn't work either.

What am I doing wrong?

I'm sorry, but I'm making a project with react native, so I don't know Swift and objective c well.

1 Answers

if you want to change a background with a custom color you should use :

someView.backgroundColor = UIColor(named: "testColor1")

Related