? ?UI總結(jié)-導(dǎo)航控制器NavigationController
今天回顧了一下導(dǎo)航控制器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];
//設(shè)置導(dǎo)航試圖控制器的外觀樣式
//下面的這個(gè)屬性是設(shè)置導(dǎo)航控制器是否為半透明,這個(gè)屬性會(huì)影響試圖的坐標(biāo)系:默認(rèn)情況是半透明,試圖的起點(diǎn)坐標(biāo)是從屏幕的左上角開始的,當(dāng)設(shè)置為透明,起點(diǎn)坐標(biāo)是在導(dǎo)航控制器下面的左上角開始的.
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];
//修改導(dǎo)航控制器的顏色
self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
//修改里面的內(nèi)容
//self.title = @"school";
//self.navigationItem.title = @"class";
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"消息",@"通知"]];
self.navigationItem.titleView = seg;
//創(chuàng)建導(dǎo)航控制器左右兩邊的按鈕
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];
}