UIButton 导航栏属性
2015-06-27 16:08
363 查看
UIbutton title居左:[btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//导航栏背景颜色
UINavigationBar *nav = [UINavigationBarappearance];
nav.barTintColor = [UIColorcolorWithRed:247/255.0green:88/255.0blue:42/255.0alpha:1.0];
//导航栏标题颜色
NSMutableDictionary *attr = [NSMutableDictionarydictionary];
attr[NSForegroundColorAttributeName] = [UIColorwhiteColor];
[nav setTitleTextAttributes:attr];
//导航栏标题
navHome.title =@"首页";
状态栏:[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
版本判断:if ([[[UIDevicecurrentDevice] systemVersion] doubleValue]>=7.0)
{
self.edgesForExtendedLayout=UIRectEdgeNone;
}
自定义导航按钮
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = menuButton;
左边按钮:
UIButton *leftButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[leftButton setBackgroundImage:[UIImageimageNamed:@"icon_back.png"]
forState:UIControlStateNormal];
leftButton.frame =CGRectMake(50 ,30,30,30);
[leftButton addTarget:selfaction:@selector(click)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]
initWithCustomView:leftButton];
右边按钮有两个:
UIButton *rightButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[rightButton setBackgroundImage:[UIImageimageNamed:@"icon_error.png"]
forState:UIControlStateNormal];
rightButton.frame =CGRectMake(150 ,30,30,30);
UIBarButtonItem *error = [[UIBarButtonItemalloc]
initWithCustomView:rightButton];
UIButton *rightButton2 = [UIButtonbuttonWithType:UIButtonTypeCustom];
[rightButton2 setBackgroundImage:[UIImageimageNamed:@"icon_info.png"]
forState:UIControlStateNormal];
rightButton2.frame =CGRectMake(150 ,30,30,30);
UIBarButtonItem *info = [[UIBarButtonItemalloc]
initWithCustomView:rightButton2];
[self.navigationItemsetRightBarButtonItems:[NSArrayarrayWithObjects:error,info,nil]];
播放暂停按钮
UIBarButtonItem *startBtn = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemPlaytarget:selfaction:nil];
UIBarButtonItem *pauseBtn = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemPausetarget:selfaction:nil];
//导航栏背景颜色
UINavigationBar *nav = [UINavigationBarappearance];
nav.barTintColor = [UIColorcolorWithRed:247/255.0green:88/255.0blue:42/255.0alpha:1.0];
//导航栏标题颜色
NSMutableDictionary *attr = [NSMutableDictionarydictionary];
attr[NSForegroundColorAttributeName] = [UIColorwhiteColor];
[nav setTitleTextAttributes:attr];
//导航栏标题
navHome.title =@"首页";
状态栏:[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
版本判断:if ([[[UIDevicecurrentDevice] systemVersion] doubleValue]>=7.0)
{
self.edgesForExtendedLayout=UIRectEdgeNone;
}
自定义导航按钮
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = menuButton;
左边按钮:
UIButton *leftButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[leftButton setBackgroundImage:[UIImageimageNamed:@"icon_back.png"]
forState:UIControlStateNormal];
leftButton.frame =CGRectMake(50 ,30,30,30);
[leftButton addTarget:selfaction:@selector(click)forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]
initWithCustomView:leftButton];
右边按钮有两个:
UIButton *rightButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[rightButton setBackgroundImage:[UIImageimageNamed:@"icon_error.png"]
forState:UIControlStateNormal];
rightButton.frame =CGRectMake(150 ,30,30,30);
UIBarButtonItem *error = [[UIBarButtonItemalloc]
initWithCustomView:rightButton];
UIButton *rightButton2 = [UIButtonbuttonWithType:UIButtonTypeCustom];
[rightButton2 setBackgroundImage:[UIImageimageNamed:@"icon_info.png"]
forState:UIControlStateNormal];
rightButton2.frame =CGRectMake(150 ,30,30,30);
UIBarButtonItem *info = [[UIBarButtonItemalloc]
initWithCustomView:rightButton2];
[self.navigationItemsetRightBarButtonItems:[NSArrayarrayWithObjects:error,info,nil]];
播放暂停按钮
UIBarButtonItem *startBtn = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemPlaytarget:selfaction:nil];
UIBarButtonItem *pauseBtn = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemPausetarget:selfaction:nil];
相关文章推荐
- UIView的layoutSubviews和drawRect方法何时调用
- 如何自己编写一个easyui插件续
- UIImageView UIButton之间的区别
- xcode7 UI 测试
- 求出最长非降子序列的长度--LIS:longest increasing subsequence
- UIView的属性方法解释(全)
- iOS开发之使用UIView-Positioning简化页面布局
- 【后缀自动机】 CodeForces 235C Cyclical Quest
- AndroidのBuild工具之Ant动手实践
- AndroidのUI体验之上拉下拉
- AndroidのUI体验之ImmersiveMode沉浸模式
- AndroidのUI布局之layout weight
- STM32F030系列UID
- iOS开发之使用UIView-Positioning简化页面布局
- 黑马程序员--Java学习日记之GUI(图形化用户界面编程)
- UIView的xib和UIViewController的xib的区别
- easyui datagrid显示进度条控制操作
- 泛型容器单元(Generics.Collections)[2]: TQueue<T> 队列列表
- RequireJS 参考文章
- require.js的用法