IOS自定義導航按鈕和標題

title爲圖片時:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];

imageView.image = [UIImage imageNamed:@"daohangtitle"];

self.navigationItem.titleView = imageView;

title爲文字時:

UILabel *tittle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

[tittle setBackgroundColor:[UIColor clearColor]];

[tittle setTextColor:[UIColor whiteColor]];

tittle.text=@"首頁";

[tittle setTextAlignment:NSTextAlignmentCenter];

[tittle setFont:[UIFont systemFontOfSize:24]];

self.navigationItem.titleView=tittle;

自定義左右按鈕

UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];

[btnLeft setFrame:CGRectMake(0, 0, 33, 31)];

 [btnLeft setBackgroundImage:[UIImage imageNamed:@"btn_go"] forState:UIControlStateNormal];

 [btnLeft setBackgroundImage:[UIImage imageNamed:@"btn_go_hig"] forState:UIControlStateSelected];

 [btnLeft addTarget:self action:@selector(didMore) forControlEvents:UIControlEventTouchUpInside];

 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];

//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章