user3904840
user3904840

Reputation: 169

RGB Problems Occurring in Swift

I'm unable to see any colors besides black when I execute the following code. It is basically to make my own custom color palette. Can anyone help and tell me why this is happening? I only see white instead of grey, pink, purple, etc. I've tried changing RGB values, but it doesn't work at all.

import UIKit

extension UIColor{
    class func myRedColor() -> UIColor{
        return UIColor (red : 252, green : 69, blue : 85, alpha : 1)
    }
    class func myOrangyColor() -> UIColor{
        return UIColor (red : 250, green : 103, blue : 59, alpha : 1)
    }
    class func myLessOrangyColor() -> UIColor{
        return UIColor (red : 252, green : 153, blue : 82, alpha : 1)
    }
    class func myYellowyColor() -> UIColor{
        return UIColor (red : 253, green : 195, blue : 53, alpha : 1)
    }
    class func myYellowColor() -> UIColor{
        return UIColor (red : 254, green : 211, blue : 62, alpha : 1)
    }
    class func myDarkGreenColor() -> UIColor{
        return UIColor (red : 40, green : 187, blue : 33, alpha : 1)
    }
    class func myLightGreenColor() -> UIColor{
        return UIColor (red : 82, green : 230, blue : 80, alpha : 1)
    }
    class func myLightBlueColor() -> UIColor{
        return UIColor (red : 92, green : 218, blue : 224, alpha : 1)
    }
    class func myDarkBlueColor() -> UIColor{
        return UIColor (red : 112, green : 189, blue : 248, alpha : 1)
    }
    class func myDarkestBlueColor() -> UIColor{
        return UIColor (red : 60, green : 116, blue : 219, alpha : 1)
    }
    class func myPurpleColor() -> UIColor{
        return UIColor (red : 123, green : 118, blue : 230, alpha : 1)
    }
    class func myVioletColor() -> UIColor{
        return UIColor (red : 217, green : 80, blue : 214, alpha : 1)
    }
    class func myPinkColor() -> UIColor{
        return UIColor (red : 237, green : 92, blue : 159, alpha : 1)
    }
    class func myGreyColor() -> UIColor{
        return UIColor (red : 197, green : 197, blue : 197, alpha : 1)
    }
    class func myBlackColor() -> UIColor{
        return UIColor (red : 0, green : 0, blue : 0, alpha : 1)
    }
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.myPurpleColor()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

Upvotes: 0

Views: 117

Answers (1)

Matthias Bauch
Matthias Bauch

Reputation: 90117

The range of the red, green and blue parameter is 0-1 as well. So instead of writing 123 you have to divide 123 by 255.

UIColor (red : 252/255.0, green : 69/255.0, blue : 85/255.0, alpha : 1)

Upvotes: 1

Related Questions