0
我正在嘗試使用某些自定義創建的漸變UIcolors
我創建的,但是當我運行該應用程序時,所有顯示的都是白色。我創建了應用程序委託的顏色,所以我可以通過使用出來的應用程序,這是我用他們的代碼:基於顏色的漸變不起作用
//AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
+ (UIColor*)blueColor1;
+ (UIColor*)blueColor2;
+ (UIColor*)yellowColor1;
@property (strong, nonatomic) UIWindow *window;
@end
//AppDelegate.m
+ (UIColor*)blueColor1 {
return [UIColor colorWithRed:112.0/255.0 green:184.0/255.0 blue:255.0/255.0 alpha:1.0];
}
+ (UIColor*)blueColor2 {
return [UIColor colorWithRed:190.0/255.0 green:243.0/255.0 blue:250.0/255.0 alpha:1.0];
}
+ (UIColor*)yellowColor1 {
return [UIColor colorWithRed:245.0/255.0 green:243.0/255.0 blue:204.0/255.0 alpha:1.0];
}
而對於梯度本身我用這個:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[AppDelegate blueColor1], (id)[AppDelegate blueColor2], (id)[AppDelegate yellowColor1], nil];
[self.view.layer insertSublayer:gradient atIndex:0];
什麼我需要做些什麼才能讓漸變顯示?
你真的想使用Objective-C的收集文字:不是'[NSArray的arrayWithObjects:這個,那個,零]',使用'@ [這個,那個] '。 – jcaron
[CAGradientLayer not working]可能重複(http://stackoverflow.com/questions/33060648/cagradientlayer-not-working) – Larme