ios 导航栏 推出

// AppDelegate.h

#import@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end

-------------

// ViewController.m

#import "ViewController.h"

#import "NBLScrollTabController.h"

#import "DemoViewController0.h"

#import "DemoViewController1.h"

#import "DemoViewController2.h"

#import "DemoViewController3.h"

@interface ViewController ()@property (nonatomic, strong) NBLScrollTabController *scrollTabController;

@property (nonatomic, strong) NSArray *viewControllers;

@end

@implementation ViewController

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeNone;

    self.title = @"NBLScrollTabDemo";

    [self.view addSubview:self.scrollTabController.view];


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [self.scrollTabController updateTabTitle:@"test" atIndex:2];//可以动态更新标题

    });

}

- (NBLScrollTabController *)scrollTabController

{

    if (!_scrollTabController) {

        _scrollTabController = [[NBLScrollTabController alloc] init];

        _scrollTabController.view.frame = self.view.bounds;

        _scrollTabController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        _scrollTabController.delegate = self;

        _scrollTabController.viewControllers = self.viewControllers;

    }


    return _scrollTabController;

}

- (NSArray *)viewControllers

{

    if (!_viewControllers) {

        DemoViewController0 *demo0 = [[DemoViewController0 alloc] init];

        NBLScrollTabItem *demo0Item = [[NBLScrollTabItem alloc] init];

        demo0Item.title = @"新闻";

        demo0Item.hideBadge = NO;//每个title可以做个性化配置

        demo0.tabItem = demo0Item;


        DemoViewController1 *demo1 = [[DemoViewController1 alloc] init];

        NBLScrollTabItem *demo1Item = [[NBLScrollTabItem alloc] init];

        demo1Item.title = @"体育";

        demo1Item.hideBadge = YES;

        demo1.tabItem = demo1Item;


        DemoViewController2 *demo2 = [[DemoViewController2 alloc] init];

        NBLScrollTabItem *demo2Item = [[NBLScrollTabItem alloc] init];

        demo2Item.title = @"娱乐";

        demo2Item.hideBadge = YES;

        demo2Item.textColor = [UIColor blackColor]; //每个title可以做个性化配置

        demo2Item.highlightColor = [UIColor yellowColor];//每个title可以做个性化配置

        demo2.tabItem = demo2Item;


        DemoViewController3 *demo3 = [[DemoViewController3 alloc] init];

        NBLScrollTabItem *demo3Item = [[NBLScrollTabItem alloc] init];

        demo3Item.title = @"八卦";

        demo3Item.hideBadge = YES;

        demo3Item.font = [UIFont systemFontOfSize:10];//每个title可以做个性化配置

        demo3.tabItem = demo3Item;


        DemoViewController1 *demo4 = [[DemoViewController1 alloc] init];

        NBLScrollTabItem *demo4Item = [[NBLScrollTabItem alloc] init];

        demo4Item.title = @"测试长度哈哈";

        demo4Item.hideBadge = YES;

        demo4.tabItem = demo4Item;


        DemoViewController2 *demo5 = [[DemoViewController2 alloc] init];

        NBLScrollTabItem *demo5Item = [[NBLScrollTabItem alloc] init];

        demo5Item.title = @"测试长度哈哈234fsdf";

        demo5Item.hideBadge = YES;

        demo5.tabItem = demo5Item;

        _viewControllers = @[demo0, demo1, demo2, demo3, demo4, demo5];

    }


    return _viewControllers;

}

#pragma mark - NBLScrollTabControllerDelegate

- (void)tabController:(NBLScrollTabController * __nonnull)tabController

didSelectViewController:( UIViewController * __nonnull)viewController

{

    //业务逻辑处理

}

@end

-----------------

// main.m#import#import "AppDelegate.h"

int main(int argc, char * argv[]) {

    @autoreleasepool {

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    }

}

---------

#import "DemoViewController0.h"

@interface DemoViewController0 ()

@end

@implementation DemoViewController0

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];

--------

推出

// AppDelegate.h

#import@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end

----

// AppDelegate.m

#import "AppDelegate.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    UINavigationController *nav =[[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];

    self.window.rootViewController = nav;

    [self.window makeKeyAndVisible];

    return YES;

}

-------

// ViewController.m

#import "ViewController.h"

#import "CLPopViewController.h"

@interface ViewController ()/** <#注释#> */

@property (nonatomic,strong) CLPopViewController *itemPopVC;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];


    self.view.backgroundColor = [UIColor yellowColor];


    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightBarAction)];

}

-(void)rightBarAction

{

    self.itemPopVC = [[CLPopViewController alloc] initWithNibName:@"CLPopViewController" bundle:nil];

    self.itemPopVC.modalPresentationStyle = UIModalPresentationPopover;

    self.itemPopVC.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem;

    //箭头方向

    self.itemPopVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;

    //代理

    self.itemPopVC.popoverPresentationController.delegate = self;

    [self presentViewController:self.itemPopVC animated:YES completion:nil];


}

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller

{

    NSLog(@"%@",controller);

    return  UIModalPresentationNone;

}

@end

------

// CLPopViewController.h

#import@interface CLPopViewController : UIViewController

@end

---

// CLPopViewController.m

#import "CLPopViewController.h"

@interface CLPopViewController ()@property (weak, nonatomic) IBOutlet UITableView *leftCell;

@property (strong, nonatomic) UITableView *tableView;

@property (strong, nonatomic) NSMutableArray *addArray;

@end

@implementation CLPopViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];

    [self.view addSubview:self.tableView];

    self.tableView.dataSource = self;

    self.tableView.delegate = self;

    self.tableView.scrollEnabled = NO;

    self.tableView.backgroundColor = [UIColor yellowColor];

    self.addArray = [[NSMutableArray alloc] initWithObjects:@"扫一扫",@"加好友", @"创建讨论组",@"发送到电脑", @"面对面快传",@"收钱", nil];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.addArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


        static NSString *identifer = @"cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];

        if (cell == nil) {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];

        }

        cell.textLabel.text = [NSString stringWithFormat:@"%@", self.addArray[indexPath.row]];

        return cell;

}

//重写preferredContentSize,返回popover的大小

- (CGSize)preferredContentSize {

    if (self.presentingViewController && self.tableView != nil) {

        CGSize tempSize = self.presentingViewController.view.bounds.size;

        tempSize.width = 150;

        CGSize size = [self.tableView sizeThatFits:tempSize];  //sizeThatFits返回的是最合适的尺寸,但不会改变控件的大小

        return size;

    }else {

        return [super preferredContentSize];

    }

}

@end

你可能感兴趣的:(ios 导航栏 推出)