-1

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

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

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];
4

1 回答 1

2

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

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

更好的是使用 UINavigationBar 外观将其应用于应用程序中使用的所有 UINavigationController。

于 2013-10-14T20:46:39.190 回答