iOS中Navbar设置渐变色效果的方法示例
时间:2021-04-27 09:08:07|栏目:iOS代码|点击: 次
本文主要给大家介绍了关于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]; }
总结
栏 目:iOS代码
本文地址:http://www.codeinn.net/misctech/109689.html