你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 導航欄顏色漸變

iOS 導航欄顏色漸變

編輯:IOS開發綜合

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate>
@property (nonatomic,strong)UIImageView * back;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //設置透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    //設置顏色
    //self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    
    self.navigationItem.title = @"哈哈哈哈哈";
    
    _back = self.navigationController.navigationBar.subviews.firstObject;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.automaticallyAdjustsScrollVieWinsets = NO;
    UITableView * tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    tableView.delegate =self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:tableView];
    
    UIImageView * image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"7b8ccd89ea7a7eca7020383ee1a0089e.jpg"]];
    image.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 150);
    tableView.tableHeaderView = image;
    
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = [[NSString alloc]initWithFormat:@"%ld",indexPath.row];
    
    return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    //從有色變無色  上面必須先設置顏色
   // _back.alpha = 1 - scrollView.contentOffset.y/1000;
    
    
    //從無色變有色  上面必須先設置透明
    NSLog(@"%f",scrollView.contentOffset.y);
    _back.alpha = scrollView.contentOffset.y/1000;
    _back.backgroundColor = [UIColor redColor];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

以上就是IOS 導航欄顏色漸變的全文介紹,希望對您學習和使用IOS應用開發有所幫助.

【iOS 導航欄顏色漸變】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved