本文主要給大家介紹了關于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];}
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林網的支持。
新聞熱點
疑難解答