iOS 自定义navigationItem


-(void)configNavigationBar

{

//建立customView

    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/2, 42)];


    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];

    [btn addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];

    [customView addSubview:btn];


    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(42, 0, SCREEN_WIDTH/2 - 42, 42)];

    imageV.image = [UIImage imageNamed:@"logo"];

    [customView addSubview:imageV];

    

    UIBarButtonItem *navLeftButton = [[UIBarButtonItem alloc] initWithCustomView:customView];

    ((UINavigationController *)contain.mainVC).viewControllers[0].navigationItem.leftBarButtonItem = navLeftButton;

    

}


你可能感兴趣的:(ios学习-UI基础学习,ios)