uinavigationcontroller

uinavigationcontroller

  self.navigationController.navigationBarHidden = YES;
self.navigationController.toolbarHidden = NO;


//titleTextAttributes(ios5.0以后可用)这是UINavigationBar的一个属性,通过它你可以设置title部分的字体、字号、阴影等
@property(nonatomic,copy) NSDictionary *titleTextAttributes NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; //UINavigationBar的这个属性可以设置navigation的内容和其中的按钮的颜色
@property(nonatomic,retain) UIColor *tintColor; 代码调用:
  NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor redColor] forKey:UITextAttributeTextColor];
self.navigationController.navigationBar.titleTextAttributes = dict;
self.navigationItem.hidesBackButton = YES; self.navigationController.navigationBar.tintColor = [UIColor greenColor];
@property(nonatomic,copy)   NSString        *title;     //导航栏的标题
@property(nonatomic,retain) UIView *titleView; //导航栏的自定义视图,设定之后title就没效果了
@property(nonatomic,copy) NSString *prompt; //设置了这个属性值之后,导航栏会加高30,在导航栏标题上方显示该值
@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;//自定义导航栏的左按钮,默认是返回按钮
@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;//自定义导航栏的左按钮,默认是没有东西显示 //代码示例如下
self.navigationItem.title = @"Root"; //设置标题,其实效果和self.title = @"Root";差不多
self.navigationItem.prompt =@"prompt test"; //在导航栏中添加segment
NSArray *array = [NSArray arrayWithObjects:@"12",@"34", nil];
UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];
segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;
[segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segmentedController; //左按钮
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectLeftAction:)];
self.navigationItem.leftBarButtonItem = leftButton; //右按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRightAction:)];
self.navigationItem.rightBarButtonItem = rightButton; //下面这两个属性设置可同时设置多个左、右按钮,设置方法和单个的差不多,只是先给归类到一个数组中;不过最好不要和设置单个的混合使用
@property(nonatomic,copy) NSArray *leftBarButtonItems NS_AVAILABLE_IOS(5_0);//设置多个左按钮,从左往右排列
@property(nonatomic,copy) NSArray *rightBarButtonItems NS_AVAILABLE_IOS(5_0);//设置多个左按钮,从右往左排列 代码示例:
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:leftButton,leftButton1, nil];
//代码示例:

self.navigationController.toolbarHidden = NO;

UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
//这个可使UIBarButtonItem自适应排列
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];
04-16 21:09