LoginSignup
15
14

More than 5 years have passed since last update.

UIColorでRGBをHex(16進数)で指定出来てアルファもキメちゃうマクロ

Last updated at Posted at 2013-11-28

下記をpchファイルに書いといて、どっからでも使えるようにした。
マクロなのでビルド時にキメの値が返るだけで、起動動的に色を動的に変更したい場合はメソッドにしておく必要がある。

//RGB color macro
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

こんな感じで使う

self.view.backgroundColor = UIColorFromRGB(0xCECECE);
self.view.backgroundColor = UIColorFromRGBWithAlpha(0xCECECE, 0.8);
15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14