本文主要给大家介绍了关于iOS中Navbar设置渐变色效果的相关内容,分享出来供大家参考学习,下面来看看详细的介绍吧。
设置渐变色
#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];}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对VEVB武林网的支持。
新闻热点
疑难解答