ios 如何设置navbar渐变背景色
答案:1 悬赏:70 手机版
解决时间 2021-02-06 10:54
- 提问者网友:记得曾经
- 2021-02-05 20:08
ios 如何设置navbar渐变背景色
最佳答案
- 五星知识达人网友:过活
- 2021-02-05 20:37
#import "NavigationViewController.h"
#define LBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
@interface NavigationViewController ()
@end
@implementation NavigationViewController
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationBar.translucent = YES;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
UIColor *color1= LBColor(255, 70, 93);
UIColor *color2 = LBColor(251, 108, 42);
gradientLayer.colors = @[(__bridge id)color1.CGColor, (__bridge id)color2.CGColor];
gradientLayer.locations = @[@0.5, @1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, -20, self.view.frame.size.width, 64);
[self.navigationBar.layer addSublayer:gradientLayer];
}追问添加渐变色后,navbar上的控件都看不到(还可以点),要怎么处理?
#define LBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
@interface NavigationViewController ()
@end
@implementation NavigationViewController
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationBar.translucent = YES;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
UIColor *color1= LBColor(255, 70, 93);
UIColor *color2 = LBColor(251, 108, 42);
gradientLayer.colors = @[(__bridge id)color1.CGColor, (__bridge id)color2.CGColor];
gradientLayer.locations = @[@0.5, @1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, -20, self.view.frame.size.width, 64);
[self.navigationBar.layer addSublayer:gradientLayer];
}追问添加渐变色后,navbar上的控件都看不到(还可以点),要怎么处理?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯