iOS 自定制导航栏 以及左右按钮 方便快捷 直接使用
来源:互联网 发布:淘宝清退中小卖家 编辑:程序博客网 时间:2024/05/22 13:23
#import "superViewController.h"
#define isIos7 ([[[UIDevice currentDevice] systemVersion] floatValue])
#define StatusbarSize ((isIos7 >= 7 && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1)?20.f:0.f)
- (void)viewDidLoad
{
[super viewDidLoad];
//判断iOS 系统
_nSpaceNavY =20;
if (isIos7 >= 7 &&__IPHONE_OS_VERSION_MAX_ALLOWED >__IPHONE_6_1)
{
_nSpaceNavY = 0;
}
}
//自定制方法-(void)createNavigationBarWithTitle:(NSString *)title andMenuItem:(UIView * (^)(int index))item
{
UIImageView *navBar = [[UIImageView alloc]initWithFrame:CGRectMake(0, _nSpaceNavY, CGRectGetWidth(self.view.frame), 64 - _nSpaceNavY)];
navBar.tag = 98;
[navBar setBackgroundColor:[UIColor colorWithHexString:@"#de5946"]];
[self.view addSubview:navBar];
// [self reloadImage];
/*导航条*/
_navView = [[UIView alloc] initWithFrame:CGRectMake(0.f, StatusbarSize, CGRectGetWidth(self.view.frame), 44.f)];
_navView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_navView];
_navView.userInteractionEnabled = YES;
if (title != nil)
{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((CGRectGetWidth(_navView.frame) - 200)/2, (CGRectGetHeight(_navView.frame) - 40)/2, 200, 40)];
[titleLabel setText:title];
[titleLabel setTextAlignment:NSTextAlignmentCenter];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[_navView addSubview:titleLabel];
}
UIView *item1 = item(0);
if (item1 != nil)
{
[_navView addSubview:item1];
}
UIView *item2 = item(1);
if (item2 != nil)
{
[_navView addSubview:item2];
}
}
//调用示例
[self createNavigationBarWithTitle:@"编辑课表" andMenuItem:^UIView *(int index) {
if (index == 1)
{
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
backButton.frame = CGRectMake(4, 6, 32, 32);
[backButton addTarget:self action:@selector(backToSuperView) forControlEvents:UIControlEventTouchUpInside];
return backButton;
}
if (index == 0)
{
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"添加(1)"] forState:UIControlStateNormal];
backButton.frame = CGRectMake(self.view.frame.size.width-38, 6, 32, 32);
[backButton addTarget:self action:@selector(submitInformation) forControlEvents:UIControlEventTouchUpInside];
return backButton;
}
return nil;
}];
- iOS 自定制导航栏 以及左右按钮 方便快捷 直接使用
- iOS自定制导航栏返回按钮或者隐藏导航栏pop手势失效解决方案
- iOS 纯代码定制 UINavigationController导航栏 左按钮又按钮以及中间的标题
- iOS添加左右导航按钮
- 自定交导航栏的左右按钮
- 解决iOS导航栏左右按钮偏移问题
- iOS 导航栏定制
- IOS中导航的返回按钮定制
- iOS-系统导航栏字体修改及自定制导航栏
- IOS设置导航栏全局的背景图片、导航栏title文字颜色大小、导航栏左右按钮的颜色。
- 导航栏添加左右按钮方法
- 自定义导航栏的左右按钮
- 导航栏左右按钮颜色设置(使用默认的按钮)
- 定制导航栏的返回按钮
- 定制导航栏的返回按钮
- 定制导航栏的返回按钮
- 定制导航栏的返回按钮
- 定制导航栏的返回按钮
- Android - 实现图片圆角显示的几种方式
- Android 6.0权限的获取
- ESP8266烧写注意事项
- Class.getResource和ClassLoader.getResource的区别分析
- iOS二维码生成中间带图片Logo
- iOS 自定制导航栏 以及左右按钮 方便快捷 直接使用
- Android仿美团加载数据、小人奔跑进度动画对话框(附顺丰快递员奔跑效果)
- [LeetCode]Power of Four
- mybatis存入数据库后没有时分秒时间不全只有年月日
- JDK1.7新特性(二)Fork/Join框架demo
- 上传大文件 NSInputStream
- 关于thinkcmf(挖个坑)
- MapReudce源码分析之Mapper
- c++ 字符串连接问题