#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
//隐藏系统导航栏
navigation.navigationBarHidden = YES;
self.window.rootViewController = navigation; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
#import "RootViewController.h"
#import "LFNavigationView.h"
#import "ViewController.h"
@interface RootViewController ()<LFNavigationViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableView;
}
@property(nonatomic, strong) LFNavigationView *navigationView; @end @implementation RootViewController - (void)loadView{
[super loadView];
_tableView = [[UITableView alloc] initWithFrame:/*[[UIScreen mainScreen] bounds]*/CGRectMake(, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - ) style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
} - (void)viewDidLoad {
[super viewDidLoad];
if([UIDevice currentDevice].systemVersion.floatValue >= ) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.modalPresentationCapturesStatusBarAppearance = NO;
}
[self setNavMethod];
} - (void)setNavMethod{
_navigationView = [[LFNavigationView alloc] initWithTitle:@"测试" WithLeftImage:nil WithLeftImageHighlighted:nil WithRightImage:nil WithRightImageHighlighted:nil WithViewControl:self];
[self.view addSubview:_navigationView];
} #pragma mark -- UITableViewDelegate --
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return ;
} - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"test row:%lu",indexPath.row];
return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@protocol  LFNavigationViewDelegate <NSObject>

@optional
- (void)leftButtonAction:(UIButton *)button;//左边按钮点击
- (void)rightButtonAction;//右边按钮点击 @end @interface LFNavigationView : UIView @property(nonatomic, weak) UIButton *leftBtn;
@property(nonatomic, weak) UIButton *rigthBtn;
@property(nonatomic, strong) UIImageView *rigthImg;
@property(nonatomic, strong) UILabel *rigthLabel;
@property(nonatomic, strong) UILabel *titleLabel; - (id)initWithTitle:(NSString*)title WithLeftImage:(NSString*)leftImage WithLeftImageHighlighted:(NSString*)leftImageHighlighted WithRightImage:(NSString*)rightImage WithRightImageHighlighted:(NSString*)rigthImagehighlighted WithViewControl:(id<LFNavigationViewDelegate>) delegate; @end
#import "LFNavigationView.h"

@implementation LFNavigationView

- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) { }
return self;
} - (id)initWithTitle:(NSString*)title WithLeftImage:(NSString*)leftImage WithLeftImageHighlighted:(NSString*)leftImageHighlighted WithRightImage:(NSString*)rightImage WithRightImageHighlighted:(NSString*)rigthImagehighlighted WithViewControl:(id<LFNavigationViewDelegate>) delegate{
float Y = ;
if ([UIDevice currentDevice].systemVersion.floatValue >= ) {
Y = ;
}
self = [super initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, +Y)];
if (self) {
UIView *bgView = [[UIView alloc] initWithFrame:self.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"顶栏背景"]];
[self addSubview:bgView]; if (title) {
//标题
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width - )/, Y, , )];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.text = title;
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = [UIFont systemFontOfSize:];
[self addSubview:_titleLabel];
} if (leftImage) {
UIImageView *leftImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",leftImage]] highlightedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",leftImageHighlighted]]];
leftImg.frame =CGRectMake(, , , );
[self addSubview:leftImg];
UIImageView *leftTapView = [[UIImageView alloc] initWithFrame:CGRectMake(, +Y, , )];
leftTapView.userInteractionEnabled = YES;
leftTapView.backgroundColor = [UIColor clearColor];
[self addSubview:leftTapView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:delegate action:@selector(leftButtonAction:)];
tapGesture.numberOfTouchesRequired = ;
tapGesture.numberOfTapsRequired = ;
[leftTapView addGestureRecognizer:tapGesture];
}
} if (rightImage) {
_rigthImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",rightImage]] highlightedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",rigthImagehighlighted]]];
_rigthImg.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-, , , );
[self addSubview:_rigthImg]; _rigthLabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - , , , )];
_rigthLabel.textColor = [UIColor whiteColor];
_rigthLabel.font = [UIFont systemFontOfSize:];
[self addSubview:_rigthLabel]; UIImageView *rightTapView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - , +Y, , )];
rightTapView.userInteractionEnabled = YES;
rightTapView.backgroundColor = [UIColor clearColor];
[self addSubview:rightTapView];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:delegate action:@selector(rightButtonAction)];
tapGesture.numberOfTouchesRequired = ;
tapGesture.numberOfTapsRequired = ;
[rightTapView addGestureRecognizer:tapGesture];
} return self;
} @end
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end
#import "ViewController.h"
#import "LFNavigationView.h"
@interface ViewController ()<LFNavigationViewDelegate> @property(nonatomic, strong) LFNavigationView *navigationView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
[self setNavMethod];
} - (void)setNavMethod{
_navigationView = [[LFNavigationView alloc] initWithTitle:@"控制器" WithLeftImage:@"返回按钮" WithLeftImageHighlighted:@"返回按钮_down" WithRightImage:@"加号图标" WithRightImageHighlighted:@"加号图标_down" WithViewControl:self];
[self.view addSubview:_navigationView];
} #pragma mark -- LFNavigationViewDelegate --
- (void)leftButtonAction:(UIButton *)button{
NSLog(@"%@",button);
[self.navigationController popToRootViewControllerAnimated:YES];
} -(void)rightButtonAction{
NSLog(@"should do somthing");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
05-08 08:08