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

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

IOS導航欄顏色漸變與常用屬性

2019-11-14 18:05:29
字體:
來源:轉載
供稿:網友
  1. 導航欄背景色設置:

    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];

  2. 導航欄標題顏色字體大小

        NSMutableDictionary *attrs = [NSMutableDictionary dictionary];

        attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];

        attrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];

        [self.navigationController.navigationBar setTitleTextAttributes:attrs];

  3. 導航欄左右item

     UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStylePlain target:self action:@selector(left)];

      self.navigationItem.leftBarButtonItem = leftItem;

      UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"right" style:UIBarButtonItemStylePlain target:self action:@selector(right)];   

        self.navigationItem.rightBarButtonItem = rightItem;

  4. 導航欄item字體顏色

     self.navigationController.navigationBar.tintColor = [UIColor redColor];如果要不同item不同顏色,那么item要帶一個自定義按鈕,在設置按鈕屬性

  5. 當前控制器的下一個控制的返回item去掉文字只保留箭頭

        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(back)];

     self.navigationItem.backBarButtonItem = backItem;

  6. 導航欄透明與導航欄底部分割線,如果有圖片高為64的話,直接設置圖片就可以了,除此之外還可以用代碼,這邊的例子全部用代碼背景色轉圖片來設置,先設置整個view的背景色為

     self.view.backgroundColor = [UIColor greenColor];如果透明看到的就是綠色。然后在分別設置

     [self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0]] forBarMetrics:UIBarMetricsDefault];

       [self.navigationController.navigationBar setShadowImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0]]];這樣就是透明的了

  7. 如果要監聽滾動而使導航欄顏色漸變,那么可以在scrollView的代理方法中添加這樣的代碼

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView

    {

         [self.navigationController.navigationBar setBackgroundImage:[self imageWithBgColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:self.tableView.contentOffset.y / 100]] forBarMetrics:UIBarMetricsDefault];

    }
    這邊用的imageWithBgColor方法

    -(UIImage *)imageWithBgColor:(UIColor *)color {

        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

        UIGraphicsBeginImageContext(rect.size);

        CGContextRef context = UIGraphicsGetCurrentContext();    

        CGContextSetFillColorWithColor(context, [color CGColor]);

        CGContextFillRect(context, rect);

         UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

         return image;

    }
    最后大致的效果點左邊是默認顏色,點右邊透明,滾動漸變,就在這記下這些了,希望有可以幫助到的地方~~




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 托克逊县| 台北县| 松江区| 芜湖市| 中山市| 沈阳市| 铁力市| 聂拉木县| 宣城市| 封开县| 巴东县| 稻城县| 咸宁市| 砚山县| 五家渠市| 宜兴市| 佛冈县| 平度市| 耿马| 任丘市| 蓬莱市| 琼海市| 克东县| 鹤壁市| 石屏县| 新乐市| 齐齐哈尔市| 汽车| 固阳县| 阿拉善盟| 莱州市| 灵丘县| 平昌县| 新沂市| 宜良县| 沭阳县| 冷水江市| 阳曲县| 黔西| 内黄县| 嘉善县|