在导航视图中。当您从左开始缓慢地滑动视图以返回父视图时,导航栏项图标可能会重叠。还有其他人遇到过同样的问题吗? https://i.stack.imgur.com/Vxmji.png 按钮也不再响应了。
置导航条上可视元素背景颜色方法:
/// 1.1 设置Bar背景颜色 以及默认BarItem的颜色
[self.navigationBar setBarTintColor:RGBCOLOR_HEX(0xf95900)];
[self.navigationBar setTintColor:[UIColor whiteColor]];
/// 1.2全局设置
UINavigationBar.appearance().barTintColor = UIColor(red: 242.0/255.0, green: 116.0/255.0, blue: 119.0/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
/// 2.1 设置导航条上的字体颜色
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:24],NSFontAttributeName, nil];
[self.navigationBar setTitleTextAttributes:attributes];
/// 2.2 全局设置方法
if let barFont = UIFont(name: "Avenir-Light", size: 24.0) {
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(), NSFontAttributeName:barFont]
/// 如果是YES, 默认状态是YES VC的子视图的y_0点将默认可视区域上移44,改为NO之后,VC的姿势图的y_0点将是导航条的y_0点。
[self.navigationBar setTranslucent:YES];
///注意:VC_A.nav pushTo VC_B 那么代码需要写在VC_A中。
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.hidesBarsOnSwipe = false
navigationController?.setNavigationBarHidden(false, animated: true)
}
/// 只需要在VC.m 中实现方法
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
/// 也可以全局的设置 两种方法 首先是代码
UIApplication.sharedApplication().statusBarStyle = .LightContent
/// 然后是plist文件修改:
Under the Info tab of the OBJect target, insert a new key named View controller-based status bar appearance and set the value to NO
///直接上代码
@class CNBarButtonItem;
typedef void(^BBIBlock)(CNBarButtonItem *barBItem);
@interface CNBarButtonItem : UIBarButtonItem
- (instancetype)barMenuButtomItem;
- (instancetype)barButtomItem:(NSString *)title;
- (void)barBlock:(BBIBlock )thisBlock;
========.h 下面是实现文件 -->.m
@implementation CNBarButtonItem{
BBIBlock _bbiBlock;
}
- (instancetype)barButtomItem:(NSString *)title {
UIButton *itemButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
[itemButton addTarget:self action:@selector(barItemEvent:) forControlEvents:UIControlEventTouchUpInside];
[itemButton setTitle:title forState:UIControlStateNormal];
[itemButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
itemButton.size = [self sizeOfBtn:itemButton];
return [self initWithCustomView:itemButton];
}
- (CGSize)sizeOfBtn:(UIButton *)btn
{
CGSize sizeBtn = [btn.titleLabel sizeThatFits:CGSizeMake(100,30)];
CGSize sizeReal = CGSizeMake(sizeBtn.width + 10, 40);
CGSize minSize = CGSizeMake(40, 40);
CGSize lastSize = sizeBtn.width + 10 > 40 ? sizeReal : minSize;
return lastSize;
}
- (void)barItemEvent:(UIButton *)btn {
if (_bbiBlock) {
_bbiBlock(self);
}
}
- (void)barBlock:(BBIBlock)thisBlock {
_bbiBlock = thisBlock;
}
=================DestVC_中使用如下
CNBarButtonItem *editItem = [[CNBarButtonItem alloc] barButtomItem:@"Edit"];
[editItem barBlock:^(CNBarButtonItem *barBItem) {
NSLog(@"Edit Click");
// [self showChannelSetView];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
CNNewsDetailViewController *_newsDetail = [[CNNewsDetailViewController alloc] init];
[self.navigationController pushViewController:_newsDetail animated:YES];
}];
UIBarButtonItem *rightSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
rightSpaceItem.width = iPhone6Plus? -15:-8;
self.navigationItem.rightBarButtonItems = @[rightSpaceItem,editItem];
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。