user3823935
user3823935

Reputation: 891

Getting error convert Hex value to RGB in Swift

code:

    vwloginView.backgroundColor =  UIColorFromRGB(52DBD1)

        func UIColorFromRGB(rgbValue: UInt) -> UIColor {
            return UIColor(
                red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
                green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
                blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
                alpha: CGFloat(1.0)
            )
        }

The above what i tried to convert to Hex value to RGB in swift.It shows error as "Expected a digit after integer literal prefix".What it is meaning?What change done to solve this problem?any help will be appreciated.thanks in advance

Upvotes: 1

Views: 943

Answers (1)

Antonio
Antonio

Reputation: 72750

52DBD1 is an hexadecimal number, so you have to tell that to the compiler, by prefixing it with 0x:

UIColorFromRGB(0x52DBD1)

Suggested reading: Numeric Literals

Upvotes: 2

Related Questions