SMTNavigationBar 1.2.1

SMTNavigationBar 1.2.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2015 年 10 月

“Steffi” 维护。



  • 作者
  • Steffi

SMTNavigationBar 简单地将自定义导航栏集中管理。创建一次导航按钮,然后就可以在任意 UIViewControllers 中访问它。

快速入门

导入
#import "UIViewController+SMTNavigationBar.h"
创建按钮
 UIButton * leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
    [leftBtn setTitle:@"left" forState:UIControlStateNormal];
    [leftBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

[self createButtonWithKey:@"leftBtn" button:leftBtn];
在导航栏中设置按钮
 [self setLeftBarButtonItemWithKey:@"leftBtn" isDefault:YES isPop:YES];
之后,您可以通过以下方式获取配置好的导航栏:

重要:始终在 viewWillAppear 中加载默认值

 -(void)viewWillAppear:(BOOL)animated{
    [self loadDefaults];
    }
单独加载默认值
/* List of items
    LEFT_ITEM
    RIGHT_ITEM
    TITLE_ITEM
    TITLEVIEW_ITEM
*/
[self loadDefaultWithItem:RIGHT_ITEM];

按钮目标选择器

使用 Blocks
[self setLeftBarButtonItemWithKey:@"leftBtn" isDefault:YES withSelectorBlock:^(UIViewController *vc) {
        //When controller is popped. VC becomes a uinavigationcontroller class.
        if([vc isKindOfClass:[UINavigationController class]]){
            UINavigationController * vcs = (UINavigationController *) vc;
            vc = [vcs viewControllers].lastObject;
        }
     NSLog(@"This is the block method generated on first VC but is now being presented in %@",vc.navigationItem.title);
     }];
注意:如果 UIViewController *vc 在 pop 后被显示出来,它会变成 UINavigationController 类。在这种情况下,请在 block 内使用此方法。
 if([vc isKindOfClass:[UINavigationController class]]){
            UINavigationController * vcs = (UINavigationController *) vc;
            vc = [vcs viewControllers].lastObject;
        }
重用 blocks
 [self runLeftSuperBlock];
 [self runRightSuperBlock];
目标选择器
在它们对应的选择器中捕获按钮控制事件。
    -(void)SMTNavigationBarDidTapLeftItem
    -(void)SMTNavigationBarDidTapRightItem
    -(void)SMTNavigationBarDidPop
创建标题视图
 UIImageView * imgView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
 imgView.contentMode = UIViewContentModeScaleAspectFill;
 imgView.clipsToBounds = NO;
 [self createTitleViewWithKey:@"titleView" titleview:imgView];
设置标题视图
 [self setTitleViewWithKey:@"titleView" isDefault:YES];
设置标题
[self setTitle:@"ABC" isDefault:YES];
查看示例项目以获取更详细实现信息

版本

1.2

变更日志

v.1.2

  • 添加了标题视图自定义
  • 增加了对导航标题的支持
  • 增加了逐个加载默认项目
  • 在重置和清除中包含新的标题视图和标题。

v.1.0

  • 设置栏项目
  • 栏项目块选择器
  • 重置值
  • 清除导航栏

下一步

  • 导航栏配置
  • Swift对应版本
  • 更好的文档编写

贡献者

riza027 - https://github.com/riza027/

一起构建吧!

分叉,实现,发起Pull Request。

版权

版权所有 (c) 2015 Steffi Tan
有关详细信息,请参阅MIT-LICENSE。