国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

設置導航欄漸變色

2019-11-06 09:58:00
字體:
來源:轉載
供稿:網友

以下方法可用來設置導航欄上的漸變色。

- (void)setNavigationBarBackgroundColor{

    //  創建 UIView用來承載漸變色放置在導航欄上時需要上移20否則狀態欄會露出

    UIView *myTopView = [[UIView alloc]initWithFrame:CGRectMake(0, -20,WIDTH ,64)];

//1、window 沒有設置導航控制器為根視圖的情況下

#if 0 

[self.view addSubview:myTopView];

//2、設置了導航控制器為根視圖。在AppDelegate中設置了

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[ViewController new]];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

#else  //則視圖添加在navigationBar上 或者其他方法設置在navigationBar處

    [self.navigationController.navigationBar addSubview:myTopView];

#endif

    // 創建漸變色圖層

    CAGradientLayer *gradientLayer= [CAGradientLayer layer];

    gradientLayer.frame       =CGRectMake(0,0,WIDTH,64);

  

    gradientLayer.colors =@[

                             (id)[UIColor yellowColor].CGColor,

                             (id)[UIColor cyanColor].CGColor

                             ];

    /* The start and end points of the gradient when drawn into the layer's

     * coordinate space. The start point corresponds to the first gradient

     * stop, the end point to the last gradient stop. Both points are

     * defined in a unit coordinate space that is then mapped to the

     * layer's bounds rectangle when drawn. (I.e. [0,0] is the bottom-left

     * corner of the layer, [1,1] is the top-right corner.) The default values

     * are [.5,0] and [.5,1] respectively. Both are animatable.

     */

    // 設置漸變方向(0~1)默認位置為 (0.5,0) 和 (0.5,1)

    gradientLayer.startPoint =CGPointMake(0,0);

    gradientLayer.endPoint =CGPointMake(0,1);

    

    // 設置漸變色的起始位置和終止位置(顏色的分割點)

    /* An optional array of NSNumber objects defining the location of each

     * gradient stop as a value in the range [0,1]. The values must be

     * monotonically increasing. If a nil array is given, the stops are

     * assumed to sPRead uniformly across the [0,1] range. When rendered,

     * the colors are mapped to the output colorspace before being

     * interpolated. Defaults to nil. Animatable. */

    gradientLayer.locations =@[@(0.15f),@(0.98f)];

    //漸變色圖層的線寬

    gradientLayer.borderWidth  =0.0;

    

    // 添加圖層

    [myTopView.layer addSublayer:gradientLayer];

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河东区| 罗田县| 临沂市| 牡丹江市| 临漳县| 昭平县| 壶关县| 根河市| 夏邑县| 兰考县| 曲阜市| 盐边县| 宾阳县| 兴义市| 桃源县| 绩溪县| 长武县| 红安县| 阜新市| 迭部县| 太康县| 射洪县| 新密市| 通道| 清流县| 博白县| 宜兰市| 辽中县| 濮阳市| 峨眉山市| 酉阳| 台东县| 龙胜| 大英县| 江阴市| 淄博市| 时尚| 梓潼县| 玛多县| 常宁市| 石景山区|