iOS 自定义navigationItem

来源:互联网 发布:类似我要当学霸的知乎 编辑:程序博客网 时间:2024/05/18 13:48


-(void)configNavigationBar

{

//建立customView

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


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

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

    [customView addSubview:btn];


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

    imageV.image = [UIImageimageNamed:@"logo"];

    [customView addSubview:imageV];

    

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

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

    

}


0 0
原创粉丝点击