导航栏UINavigationBar

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sndongcheng/article/details/83349893

UINavigationController、UINavigationBar、UINavigationItem



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect screen = [[UIScreen mainScreen] bounds];
    UINavigationBar *nb = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 20, screen.size.width, 44)];
    UIBarButtonItem *bb1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)];
    UIBarButtonItem *bb2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    UINavigationItem *ni = [[UINavigationItem alloc]initWithTitle:@""];
    ni.leftBarButtonItem = bb1;
    ni.rightBarButtonItem = bb2;
    nb.items = @[ni];
    [self.view addSubview:nb];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

猜你喜欢

转载自blog.csdn.net/sndongcheng/article/details/83349893