您的位置:首页 > 产品设计 > UI/UE

iOS基础控件-导航栏控制器UINavigationController的UINavigationBar导航条

2014-10-20 09:59 399 查看
/*

**UINavigationBar详解**

** barStyle -
设置导航条的样式

** clipsToBounds -
设置导航条的自动裁剪属性

** navigationBarHidden -
隐藏导航条的属性

** -(void)setNavigationgBarHidden:(BOOL)hidden
animated:(BOOL)animated

- 设置隐藏导航条属性并伴有动画效果

*/

在某个视图控制器中写的代码
- (void)viewDidLoad

{

[super
viewDidLoad];

self.view.backgroundColor
= [UIColor
yellowColor];

UIButton
*btn = [UIButton
buttonWithType:UIButtonTypeSystem];

[btn setFrame:CGRectMake(10, 50, 300, 30)];

[btn setTitle:@"pushSecond"
forState:UIControlStateNormal];

[btn setBackgroundColor:[UIColor
whiteColor]];

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

[self.view
addSubview:btn];

//设置导航条的风格样式

self.navigationController.navigationBar.barStyle
=
UIBarStyleBlack;

//设置导航条的背景颜色

self.navigationController.navigationBar.backgroundColor
= [UIColor
redColor];

/* ** iOS5.0以后才支持的给导航条设置图片的方法

** UIBarMetrics
设置iPhone
模式)(竖屏是人像模式,横屏是风景模式)@"tabbar_rank_press@2x.png"

** iOS7.0
中如果你设置的图片的尺寸大于导航条的大小,虽然clipsToBounds(自动裁剪)属性默认为NO

但是会自动裁剪图片,

手动将clipsToBounds属性置为YES后,屏幕上侧显示电池和信号的一栏会出现空白情况,

**
在iOS以前的一些版本中,导航栏控制器默认的Y坐标是从20开始的,

所以,是避开上端信息栏的。现在时全屏幕的

**
如果设置的图片的尺寸小于导航栏的大小,它会被平铺(详见WINDOWS系统中桌面的显示方式)显示在导航栏中

*/

//设置导航条的自动裁剪属性

self.navigationController.navigationBar.clipsToBounds
=NO;

//导航条的图片及其iPhone的属性

[self.navigationController.navigationBar
setBackgroundImage:[UIImage
imageNamed:@"knockout_74.jpg"]
forBarMetrics:UIBarMetricsDefault];

//设置导航条隐藏属性

/*self.navigationController.navigationBar.hidden = YES;

self.navigationController.navigationBarHidden = YES;

[self.navigationController setNavigationBarHidden:YES];*/

//伴随动画隐藏

[self.navigationController
setNavigationBarHidden:YES
animated:YES];

//设置导航条图片

//竖屏导航条 44高

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar.png"] forBarMetrics:UIBarMetricsDefault];

//横屏导航条 32高

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav-32.png"] forBarMetrics:UIBarMetricsLandscapePhone];

// Do any additional setup after loading the view.

//self.view.backgroundColor = [UIColor redColor];

}

- (void)btnClick:(UIButton
*)btn

{

XSSecondController
*secondViewController = [[XSSecondController
alloc]
init];

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐