iOS導(dǎo)航欄UINavigationBar添加進度條

??常??吹胶枚鄳?yīng)用push出新界面時,導(dǎo)航欄下方會有一個進度條顯示,所以簡單的實現(xiàn)了一下這個效果。代碼如下:


#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIProgressView *progressView;

@property (nonatomic, strong) NSTimer *longConnectTimer;

@property (nonatomic, assign) int time;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor greenColor];
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    self.navigationItem.title = @"導(dǎo)航欄進度條";
    
    
//    // 導(dǎo)航欄底部添加進度條
//    self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 43, CGRectGetWidth(self.view.frame), 40000)];// 高度設(shè)置無效,默認是2
    // 狀態(tài)欄頂部添加進度條
    self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, -20, CGRectGetWidth(self.view.frame), 40000)];// 高度設(shè)置無效,默認是2
    self.progressView.backgroundColor = [UIColor clearColor];// 背景顏色,只有trackTintColor為透明色時,才能看到背景顏色
    self.progressView.progressTintColor = [UIColor purpleColor];// 進度部分的顏色
    self.progressView.trackTintColor = [UIColor clearColor];// 未進度部分的顏色
    
//    [self.navigationController.navigationBar addSubview:self.progressView];// 導(dǎo)航欄添加進度條方式一
    [self.navigationController.navigationBar.layer addSublayer:self.progressView.layer];// 導(dǎo)航欄添加進度條方式二


    self.time = 0;
    self.longConnectTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(longConnectToSocket) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.longConnectTimer forMode:NSRunLoopCommonModes];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)longConnectToSocket {
    self.time += 25;
    [self.progressView setProgress:(self.time / 100.0) animated:YES];
    if (100 == self.time) {
        self.time = 0;
    }
}

問題一: 不知道大家有沒有更好的實現(xiàn)方式,歡迎留言

問題二:

  • 進度條的高度怎么改變??通過設(shè)置transform 屬性progressView.transform = CGAffineTransformMakeScale(1.0f, 5.0f);有問題,就有進度條在進度時,一邊向有進度,一邊向下擴展高度,效果很糟糕。
  • 怎樣讓進度條鋪滿整個導(dǎo)航欄的高度(高度64)來顯示進度,但是不遮住導(dǎo)航欄上的標題和按鈕等????
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 我們要實現(xiàn)上面圖片的效果,在滑動條滑動改變的同時,進度條也跟隨著改變。 在 ViewController.h里面聲...
    來敲代碼閱讀 798評論 0 0
  • 簡介: 三姐妹安雨萱,安雨瀟,楊曉,出生在小城鎮(zhèn),卻立志要到大城市打拼,希望能擁有屬于自己的一片天地,在愛情,工作...
    琉璃花楹閱讀 626評論 17 21
  • 她怔怔的盯著那雙被擦得锃亮的黑色高級皮靴。 皮靴在耀眼的橙黃色燈光下更加閃耀。 她不知道那是什么牌子,只知道那是她...
    蘇小眠233閱讀 331評論 0 1
  • 一雙憂郁的眼睛 溫暖如燭光 照亮黑暗的陰影 暗香浮動情意綿綿 那是一場青春逃不掉的劫 相愛卻分離著苦痛 眉宇里寫滿...
    玉妮閱讀 314評論 2 4
  • 不記得哪兒看到的這句話:笑容靦腆的孩子,都很漂亮。當初看到這句話的時候,我想到了我的男朋友,但工作以來,又看到了兩...
    小懶神閱讀 452評論 0 0

友情鏈接更多精彩內(nèi)容