Created
December 21, 2011 16:32
-
-
Save nolili/1506670 to your computer and use it in GitHub Desktop.
UIColorからR,G,B,Alphaの値を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
UIColorからR,G,B,Alphaの値を取得する | |
iOS SDK 5.0 以降が必要 | |
*/ | |
// サンプルのUIColor | |
//[UIColor whitecolor]の場合カラースペースが異なるため取得できない | |
UIColor *color = [UIColor redColor]; | |
// 取得した値を保存する変数 | |
CGFloat red = 0.0; | |
CGFloat green = 0.0; | |
CGFloat blue = 0.0; | |
CGFloat alpha = 0.0; | |
// 変数のアドレスを渡す | |
// 値の取得は失敗する可能性があるので戻り値を確認する | |
if ([color getRed:&red green:&green blue:&blue alpha:&alpha]) | |
// 結果を出力 | |
NSLog(@"Red:%f Green:%f Blue:%f Alpha:%f", red, green, blue, alpha); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment