【发布时间】:2016-01-25 22:55:33
【问题描述】:
我正在尝试使用我创建的一些自定义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: this, that, nil],使用@[this, that]。
标签: ios objective-c uicolor cagradientlayer