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;
//创建导航控制器左右两边的按钮
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];
}
网友评论