自己封装了一个导航条,可以调用系统的侧滑返回
2015-04-28 15:29
399 查看
#define IsIOS7 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=7)
+(void)initWithNavViewWith:(NSString *)titleName selfView:(UIViewController
*)selfView
{
selfView.view.backgroundColor=RGBA(235.0,
235.0, 235.0,
1);
//
导航条
if (IsIOS7)
{
selfView.automaticallyAdjustsScrollViewInsets=NO;
}
selfView.navigationController.navigationBar.barStyle =
UIStatusBarStyleDefault;
[selfView.navigationController.navigationBar
setTintColor:[UIColor
whiteColor]];
UILabel *titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 100,
44)];
titleLabel.font = [UIFont
boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor
whiteColor];
titleLabel.textAlignment =
NSTextAlignmentCenter;
titleLabel.text = titleName;
selfView.navigationItem.titleView = titleLabel;
[selfView.navigationController.navigationBar
setBarTintColor:RGBA(35.0,
131.0,
221.0, 1.0)];
[selfView.navigationController.navigationBar
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor
whiteColor],NSForegroundColorAttributeName,nil]];
}
+(void)initWithNavViewWith:(NSString *)titleName left:(NSString *)nameLeft
right:(NSString *)nameRight selfView:(UIViewController *)selfView
{
selfView.view.backgroundColor=RGBA(235.0,
235.0, 235.0,
1);
//
导航条
if (IsIOS7)
{
selfView.automaticallyAdjustsScrollViewInsets=NO;
}
if (nameRight)
{
BOOL isPng = [nameRight
hasSuffix:@"png"];
if (isPng)
{
UIBarButtonItem *rightBtnItem = [[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:nameRight]
style:UIBarButtonItemStylePlain
target:selfView action:@selector(gotoNextVC)];
rightBtnItem.tintColor=[UIColor
whiteColor];
selfView.navigationItem.rightBarButtonItem = rightBtnItem;
}
else
{
UIBarButtonItem *rightBtnItem = [[UIBarButtonItem
alloc]initWithTitle:nameRight
style:UIBarButtonItemStylePlain
target:selfView action:@selector(gotoNextVC)];
rightBtnItem.tintColor=[UIColor
whiteColor];
selfView.navigationItem.rightBarButtonItem = rightBtnItem;
}
}else
{
}
UIBarButtonItem *backItem = [[UIBarButtonItem
alloc]
init];
backItem.title=nameLeft;
backItem.imageInsets =
UIEdgeInsetsMake(15,
0, 0,
0);
selfView.navigationItem.backBarButtonItem = backItem;
selfView.navigationController.navigationBar.barStyle =
UIStatusBarStyleDefault;
[selfView.navigationController.navigationBar
setTintColor:[UIColor
whiteColor]];
UILabel *titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 100,
44)];
titleLabel.font = [UIFont
boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor
whiteColor];
titleLabel.textAlignment =
NSTextAlignmentCenter;
titleLabel.text = titleName;
selfView.navigationItem.titleView = titleLabel;
[selfView.navigationController.navigationBar
setBarTintColor:RGBA(35.0,
131.0,
221.0, 1.0)];
[selfView.navigationController.navigationBar
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor
whiteColor],NSForegroundColorAttributeName,nil]];
}
//
//点击右边按钮
-(void)gotoNextVC
{
}
+(void)initWithNavViewWith:(NSString *)titleName selfView:(UIViewController
*)selfView
{
selfView.view.backgroundColor=RGBA(235.0,
235.0, 235.0,
1);
//
导航条
if (IsIOS7)
{
selfView.automaticallyAdjustsScrollViewInsets=NO;
}
selfView.navigationController.navigationBar.barStyle =
UIStatusBarStyleDefault;
[selfView.navigationController.navigationBar
setTintColor:[UIColor
whiteColor]];
UILabel *titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 100,
44)];
titleLabel.font = [UIFont
boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor
whiteColor];
titleLabel.textAlignment =
NSTextAlignmentCenter;
titleLabel.text = titleName;
selfView.navigationItem.titleView = titleLabel;
[selfView.navigationController.navigationBar
setBarTintColor:RGBA(35.0,
131.0,
221.0, 1.0)];
[selfView.navigationController.navigationBar
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor
whiteColor],NSForegroundColorAttributeName,nil]];
}
+(void)initWithNavViewWith:(NSString *)titleName left:(NSString *)nameLeft
right:(NSString *)nameRight selfView:(UIViewController *)selfView
{
selfView.view.backgroundColor=RGBA(235.0,
235.0, 235.0,
1);
//
导航条
if (IsIOS7)
{
selfView.automaticallyAdjustsScrollViewInsets=NO;
}
if (nameRight)
{
BOOL isPng = [nameRight
hasSuffix:@"png"];
if (isPng)
{
UIBarButtonItem *rightBtnItem = [[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:nameRight]
style:UIBarButtonItemStylePlain
target:selfView action:@selector(gotoNextVC)];
rightBtnItem.tintColor=[UIColor
whiteColor];
selfView.navigationItem.rightBarButtonItem = rightBtnItem;
}
else
{
UIBarButtonItem *rightBtnItem = [[UIBarButtonItem
alloc]initWithTitle:nameRight
style:UIBarButtonItemStylePlain
target:selfView action:@selector(gotoNextVC)];
rightBtnItem.tintColor=[UIColor
whiteColor];
selfView.navigationItem.rightBarButtonItem = rightBtnItem;
}
}else
{
}
UIBarButtonItem *backItem = [[UIBarButtonItem
alloc]
init];
backItem.title=nameLeft;
backItem.imageInsets =
UIEdgeInsetsMake(15,
0, 0,
0);
selfView.navigationItem.backBarButtonItem = backItem;
selfView.navigationController.navigationBar.barStyle =
UIStatusBarStyleDefault;
[selfView.navigationController.navigationBar
setTintColor:[UIColor
whiteColor]];
UILabel *titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 100,
44)];
titleLabel.font = [UIFont
boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor
whiteColor];
titleLabel.textAlignment =
NSTextAlignmentCenter;
titleLabel.text = titleName;
selfView.navigationItem.titleView = titleLabel;
[selfView.navigationController.navigationBar
setBarTintColor:RGBA(35.0,
131.0,
221.0, 1.0)];
[selfView.navigationController.navigationBar
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor
whiteColor],NSForegroundColorAttributeName,nil]];
}
//
//点击右边按钮
-(void)gotoNextVC
{
}
相关文章推荐
- thinkphp(tp)框架封装一个自己写的方法到类里面.可以在其他控制器里面调用
- 封装好的一个的Toast工具类(可以直接调用)
- ado.net调用存储过程的一个封装类(网上找的不怕只怕自己不去理解)
- 自己添加一个系统调用
- 自己写一个linux的系统调用
- Android中Activity启动模式详解,可以控制程序按home键后进来还会调用一个自己不喜欢的界面
- iOS7以上自定义一个navigationController,并沿用系统的侧滑返回效果
- 自己封装的三维AABB包围盒类,用于三维模型静态碰撞检测,可以直接调用,使用OpenGL进行绘制
- 请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程: ax2 + bx + c = 0 的两个解。 提示:计算平方根可以调用math.sqrt()函数:
- 前言 让自己的思路可以成为一个比较好的系统。而不断的改进完善。
- 闲来无事,将自己收集到的工具类封装了下,做了一个lib,写了个简单的mvp,初学者可以看看
- 整理一个自己用的Ajax例子,封装,调用!
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时为什么会回到home界面或者到前一个界面,然后才会跳转到当前activity
- 久违的json使用大法 (通常Ajax希望返回多个键值对,可以用将要返回的数据先封装到一个对象中,再将这个对象转为json格式)
- 自己写的一个图片上传类,很方便可以指定目录,系统自动创建目录,可以指定名字,类型,大小
- 封装一个cout方法,能实现如此调用:cout(a)(b)(c)(d)(e)… 并且返回的值为参数连剩的结果,即a*b*c*d*e*…。如cout(1)(3)(7) 得到21
- 【郝斌数据结构自学笔记】53-56_一个函数为什么可以自己调用自己_递归必须满足三个条件_循环和递归的比较
- 自己创建并使用一个系统调用
- Swift 调用系统相机 (自己封装的小Demo)
- 用java写的一个程序,可以调用windows系统中自带的各种工具,例如截图,便签等