6rfitq
Last Updated: June 19, 2019
·
15.81K
· itseranga

IOS UI colors with hex values in swfit

UIColorFromHex function

  • There is no any default function to define UI colors with hex values in IOS

  • Following swift function can be use to define colors with hex(RBG) values

func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
    let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
    let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
    let blue = CGFloat(rgbValue & 0xFF)/256.0

    return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}

// rbgValue - define hex color value
// alpha - define transparency value
// returns - CGColor

Function usage(set view background color)

var loadingView: UIView = UIView()
loadingView.frame = CGRectMake(0, 0, 80, 80)
loadingView.center = self.view.center

// set background color
loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.7)
  • Output would be like below

Picture

Function usage(set view border color)

  • When define border color of a view, need to convert UIColor to CGColor
var loadingView: UIView = UIView()
loadingView.frame = CGRectMake(0, 0, 80, 80)
loadingView.center = self.view.center

// set background color
loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.7)

// set border width and color
loadingView.layer.borderColor = UIColorFromHex(0xdf661d).CGColor
loadingView.layer.borderWidth = 2
  • Output would be like below

Picture

7 Responses
Add your response

30636

Thank you for sharing this article. Get mobdroapp from https://mobdroapp.one/ which lets you to watch unlimited free movies right from your android smartphone.

10 months ago ·
31880
31996

That's too cool to be true! But thanks anyways! https://kiltzone.com/

4 months ago ·
32181

Thanks for sharing the hex values http://drivemecrazy.mobi/

3 months ago ·
32193

Cool Information you have shared here. install CinemaApk on your Android. http://cinemaapk.fun/

3 months ago ·
32234

iOS colors is different to to attract the users. But Android colors are very easy and safe to handle your device. Best Example Mobdro GUI is good and also having attractive color design. You want to check it once Go here ( http://redboxtvpro.com/mobdro-apk-download/ ). Then see the images of new Mobdro User interface.

3 months ago ·
33690

Con aproximadamente 8,000 voluntarios involucrados en los Juegos Europeos 2019, los 2dos Juegos Europeos en Minsk serán el evento más importante en los eventos deportivos europeos. https://livesportworld.com/como-ver-los-partidos-europeos-en-vivo-en-linea/ Promoverá los valores olímpicos y también estilos de vida saludables.

6 days ago ·