導航欄的定義操作

導航欄設(shè)置透明

UIImage *image = [[UIImage alloc] init];[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

? ? //去掉透明后導航欄下邊的黑邊

? ? [self.navigationController.navigationBar setShadowImage:image];

? ? self.navigationController.navigationBar.barStyle = UIBarStyleDefault;

? ? self.navigationController.navigationBar.translucent = YES;


導航欄背景自定義满粗,去除下方的黑線

@property (nonatomic, strong) UIImageView * navBarHairlineImageView;

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {

? ? if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {

? ? ? ? return (UIImageView *)view;

? ? }

? ? for (UIView *subview in view.subviews) {

? ? ? ? UIImageView *imageView = [self findHairlineImageViewUnder:subview];

? ? ? ? if (imageView) {

? ? ? ? ? ? return imageView;

? ? ? ? }

? ? }

? ? return nil;

}

- (void)viewWillAppear:(BOOL)animated{

? ? _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];

? ? _navBarHairlineImageView.hidden = YES;

? ? [self.navigationController.navigationBar setBarTintColor:你的顏色];

? ? [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];

? ? self.tabBarController.tabBar.hidden = YES;

? ? [self navButton];

}

- (void)viewWillDisappear:(BOOL)animated{

? ? _navBarHairlineImageView.hidden = NO;

? ? [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithWhite:1 alpha:0.8]];

? ? [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil]];

? ? self.tabBarController.tabBar.hidden = NO;

}


返回按鈕

#pragma mark - 定義導航的按鈕

- (void)navButton{

? ? UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];

? ? leftButton.frame = CGRectMake(0, 0, 25, 25);

? ? [leftButton setImage:[UIImage imageNamed:@"back_white"] forState:0];

? ? [leftButton setBackgroundColor:[UIColor clearColor]];

? ? leftButton.titleLabel.font = [UIFont systemFontOfSize:15];

? ? [leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];

? ? UIBarButtonItem * tiem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];

? ? UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? target:nil action:nil];

? ? negativeSpacer.width = -10;

? ? self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, tiem, nil];


? ? UIButton * rightButton = [UIButton buttonWithType:UIButtonTypeCustom];

? ? rightButton.frame = CGRectMake(0, 0, 25, 25);

? ? [rightButton setImage:[UIImage imageNamed:@"search.png"] forState:0];

? ? [rightButton setBackgroundColor:[UIColor clearColor]];

? ? rightButton.titleLabel.font = [UIFont systemFontOfSize:15];

? ? [rightButton addTarget:self action:@selector(rightButtonClick) forControlEvents:UIControlEventTouchUpInside];

? ? UIBarButtonItem * tiemRight = [[UIBarButtonItem alloc]initWithCustomView:rightButton];

? ? UIBarButtonItem *negativeSpacerRight = [[UIBarButtonItem alloc]

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? target:nil action:nil];

? ? negativeSpacerRight.width = -10;

? ? self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacerRight, tiemRight, nil];

}

- (void)leftClick{

? ? [self.navigationController popViewControllerAnimated:YES];

}

- (void)rightButtonClick{


}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末颤专,一起剝皮案震驚了整個濱河市哼拔,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌蠢挡,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,907評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件凳忙,死亡現(xiàn)場離奇詭異业踏,居然都是意外死亡,警方通過查閱死者的電腦和手機消略,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評論 3 395
  • 文/潘曉璐 我一進店門堡称,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人艺演,你說我怎么就攤上這事却紧。” “怎么了胎撤?”我有些...
    開封第一講書人閱讀 164,298評論 0 354
  • 文/不壞的土叔 我叫張陵晓殊,是天一觀的道長。 經(jīng)常有香客問我伤提,道長巫俺,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,586評論 1 293
  • 正文 為了忘掉前任肿男,我火速辦了婚禮介汹,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘舶沛。我一直安慰自己嘹承,他們只是感情好,可當我...
    茶點故事閱讀 67,633評論 6 392
  • 文/花漫 我一把揭開白布如庭。 她就那樣靜靜地躺著叹卷,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上骤竹,一...
    開封第一講書人閱讀 51,488評論 1 302
  • 那天帝牡,我揣著相機與錄音,去河邊找鬼蒙揣。 笑死靶溜,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的鸣奔。 我是一名探鬼主播墨技,決...
    沈念sama閱讀 40,275評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼挎狸!你這毒婦竟也來了扣汪?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,176評論 0 276
  • 序言:老撾萬榮一對情侶失蹤锨匆,失蹤者是張志新(化名)和其女友劉穎崭别,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體恐锣,經(jīng)...
    沈念sama閱讀 45,619評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡茅主,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,819評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了土榴。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片诀姚。...
    茶點故事閱讀 39,932評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖玷禽,靈堂內(nèi)的尸體忽然破棺而出赫段,到底是詐尸還是另有隱情,我是刑警寧澤矢赁,帶...
    沈念sama閱讀 35,655評論 5 346
  • 正文 年R本政府宣布糯笙,位于F島的核電站,受9級特大地震影響撩银,放射性物質(zhì)發(fā)生泄漏给涕。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,265評論 3 329
  • 文/蒙蒙 一额获、第九天 我趴在偏房一處隱蔽的房頂上張望够庙。 院中可真熱鬧,春花似錦抄邀、人聲如沸首启。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春准夷,著一層夾襖步出監(jiān)牢的瞬間钥飞,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評論 1 269
  • 我被黑心中介騙來泰國打工衫嵌, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留读宙,地道東北人。 一個月前我還...
    沈念sama閱讀 48,095評論 3 370
  • 正文 我出身青樓楔绞,卻偏偏與公主長得像结闸,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子酒朵,可洞房花燭夜當晚...
    茶點故事閱讀 44,884評論 2 354

推薦閱讀更多精彩內(nèi)容

  • 4月03日第5天共讀第五天—張潤華 在一個愜意的環(huán)境中被動地生活所感受到的快樂桦锄,遠遠比不上那種有激情地投入到有價值...
    觸心凝眸2020閱讀 165評論 0 0
  • 一、目錄查詢查看根目錄文件 二蔫耽、賦權(quán)限 三结耀、修改文件的所有者改為etl用戶
    BestFei閱讀 146評論 0 0
  • 如果享受雨幕而不能隨性作詩寫文 那享受美好又有什么意義 重要的不只有感受 還有抒寫和記錄
    孤煙起朝嵐閱讀 52評論 0 0