UI總結-導航控制器NavigationController

? ?UI總結-導航控制器NavigationController

今天回顧了一下導航控制器NavigationController,下面是具體代碼:

#import "ViewController.h"

#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.view.backgroundColor = [UIColor whiteColor];

//設置導航試圖控制器的外觀樣式

//下面的這個屬性是設置導航控制器是否為半透明,這個屬性會影響試圖的坐標系:默認情況是半透明,試圖的起點坐標是從屏幕的左上角開始的,當設置為透明,起點坐標是在導航控制器下面的左上角開始的.

self.navigationController.navigationBar.translucent = NO;

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

view.backgroundColor = [UIColor redColor];

[self.view addSubview:view];

[view release];

//修改導航控制器的顏色

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

//修改里面的內容

//self.title = @"school";

//self.navigationItem.title = @"class";

UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"消息",@"通知"]];

self.navigationItem.titleView = seg;

//創(chuàng)建導航控制器左右兩邊的按鈕

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"title" style:UIBarButtonItemStylePlain target:self action:@selector(barAction)];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setImage:[UIImage imageNamed:@"pinglun.png"] forState:UIControlStateNormal];

button.frame = CGRectMake(0, 0, 40, 40);

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

UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(100, 100, 100, 100);

btn.backgroundColor = [UIColor redColor];

[self.view addSubview:btn];

[btn setTitle:@"下一頁" forState:UIControlStateNormal];

[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

}

-(void)barAction{

}

-(void)click:(UIButton *)button{

SecondViewController *vc = [[SecondViewController alloc]init];

[self.navigationController pushViewController:vc animated:YES];

[vc release];

}

運行結果如下:


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容