UIToolbar UINavigationController UINavigationBar UIBarButtonItem

简介: --------------------------------------------------------------------------------UIBarButtonItem----------------------------...

--------------------------------------------------------------------------------UIBarButtonItem--------------------------------------------------------------------------------

1:  UIBarButtonItem 隐藏的方式

[self.btnPunctuation setWidth:0];

2:  UIBarButtonItem 获取所在父视图中的frame 相当于将 UIBarButtonItem 转换成 UIView

UIBarButtonItem *barButtonItem = (UIBarButtonItem *)sender;
UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];


3:设置自定义字体和 系统的self.title 保持风格完全一致.

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[titleButton setBackgroundColor:[UIColor clearColor]];
[titleButton setFrame:(CGRect){0,0,100,44}];
[titleButton setContentEdgeInsets:UIEdgeInsetsMake(-2, 0, 0, 0)];
[titleButton setTitle:@"社会活动" forState:UIControlStateNormal];
[titleButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[titleButton.titleLabel setShadowOffset:(CGSize){0,-1}];
[self.navigationItem setTitleView:titleButton];

4:隐藏系统自动生成的返回按钮

self.navigationItem.hidesBackButton = YES;



--------------------------------------------------------------------------------UIBarButtonItem--------------------------------------------------------------------------------



--------------------------------------------------------------------------------UINavigationBar--------------------------------------------------------------------------------



1:  修改导航控制器背景图片的方式(IOS5以上)

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

注: 通过appearance可以设置全局的控件初始化外观.不过在初始化成功以后,有单独样式需求亦可用同样的方法修改.

UINavigationBar的标准高度是44,在iOS7之前可以通过44+X的方式实现背景+阴影的效果.从iOS7以后就不行了.

iOS7对UINavigationBar的标准进行重新的定义,其高度可以延伸到状态栏.所以44+20的高度等于64.

而刚刚说的44+X方式不再适用于iOS7,iOS7的新规范是64+1.背景图和阴影将单独来设定,代码如下:

//iOS7 新背景图片设置方法 高度 必需是 64
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"toolbar_background_iOS7Test"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
//iOS7 阴影需单独设定 UIColor clearColor 是去掉字段 1像素阴影
[self.navigationController.navigationBar setShadowImage:[UIImage Help_imageWithColor:[UIColor clearColor]]];

2:为UINavigationBar设置半透明的背景效果:

[self.navigationController.navigationBar setTranslucent:YES];
注:在iOS7中 默认生成 UINavigationBar的translucent属性为YES. 自动添加遮罩模糊效果.


3:修改UINavigationBar的背景颜色(iOS7以上)

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];



--------------------------------------------------------------------------------UINavigationBar--------------------------------------------------------------------------------



--------------------------------------------------------------------------------UINavigationController--------------------------------------------------------------------------------

1: 修改UINavigationController的高度

[self.navigationController.navigationBar setFrame:CGRectMake(0,20, 320, 60)];

2:激活 UINavigationControllerDelegate的方式

self.navigationController.delegate =self;

3:为  UINavigationController 设置 默认的  navigationBar 

这里只提供一下思路:

继承:UINavigationController以后重写 如下两个方法:

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController];
    [self Base_backAction_initNavigationBar:rootViewController];
    return self;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [super pushViewController:viewController animated:animated];
    [self Base_backAction_initNavigationBar:viewController];
}

--------------------------------------------------------------------------------UINavigationController--------------------------------------------------------------------------------


目录
相关文章
UINavigationBar-使用总结
UINavigationBar-使用总结
83 0
UINavigationController和UITabBarController合用。
UINavigationController和UITabBarController合用。
53 0
UITabBarController 获得selecdIndex
UITabBarController 获得selecdIndex
56 0
|
开发者 iOS开发
UIDatePicker的详细讲解
UIDatePicker的详细讲解
389 0
 UIDatePicker的详细讲解