skip to Main Content

can someone please tell me if I can change the color on below format using Color Set. For example, Instead of .blue, I want to use my own color set such as Color("colorname"). Is this possible

.onAppear {
UITableView.appearance().backgroundColor = .blue
}

3

Answers


  1. UITableView.appearance().backgroundColor = UIColor(named: "your set here")

    Login or Signup to reply.
  2. You could write a static extension for UIColor, like this:

    extension UIColor {
        public static let yourColor = // ... define any color here
    }
    

    You can then access this value from anywhere within your app just like the pre-defined colors (e.g. .blue, but instead of blue you use your custom name).

    Login or Signup to reply.
  3. You can create your own color like this:

    extension UIColor {
         struct rickyPurpleColor {
         static let normal = UIColor(red:0.043, green:0.576 ,blue:0.588 , alpha:1.00)
        static let light = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
        static let dark = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
        }
        }
    

    After you can use it like this:

            .onAppear {
        UITableView.appearance().backgroundColor = Color(UIColor.rickyPurpleColor.normal)
        }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search