1

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.

The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49
minami
  • 207
  • 3
  • 13
  • You can't mix Objective-C & Swift like that, one line in each language... So `animationUIView.backgroundColor = [UIColor testColor1];` should be the one, but you might need to make it visible to Objective-C: https://stackoverflow.com/questions/27097688/can-objective-c-code-call-swift-class-extensions – Larme Sep 21 '22 at 20:46

1 Answers1

0

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

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

Adi Elron
  • 37
  • 6