想在iOS的导航栏中制作渐变背景

时间:2013-10-14 20:35:37

标签: ios

我想在导航栏中制作渐变背景,两种颜色一半用浅蓝色,另一半用深蓝色。

这是我到目前为止所尝试的,

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; 
CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame = view.bounds; 
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], 
                                            (id)[[UIColor whiteColor] CGColor], 
                                            nil]; 
[view.layer insertSublayer:gradient atIndex:0];

1 个答案:

答案 0 :(得分:2)

如果您想要自定义导航栏,我建议您使用以下方法创建图像并将其设置为UINavigationBar的背景图像。

 - (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

最好使用UINavigationBar外观将其应用于应用程序中使用的所有UINavigationControllers。