美文网首页
导航条leftBarButtonItem的问题修正

导航条leftBarButtonItem的问题修正

作者: 行走在北方 | 来源:发表于2019-08-07 11:04 被阅读0次

    由于出现了按钮不是自己想要的尺寸布局

    就是把自定义的button加在View即可

    Jietu20190807-110238.png

    1、这是不正常的数据

    UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundImageFile];
        UIButton* modalViewButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 21.5, 15)];
        [modalViewButton addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
        [modalViewButton setImage:backgroundImage forState:UIControlStateNormal];
        UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: modalViewButton];
        self.navigationItem.leftBarButtonItem = modalBarButtonItem;
    

    2、这是正常的代码

        UIButton* modalViewButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 21.5, 15)];
        [modalViewButton addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
        [modalViewButton setImage:backgroundImage forState:UIControlStateNormal];
        UIView *containVew = [[UIView alloc] initWithFrame:modalViewButton.bounds];
        [containVew addSubview:modalViewButton];
        UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containVew];
        self.navigationItem.leftBarButtonItem = modalBarButtonItem;
    
    7284CA8E1080D6BADDCC07B4225CE18F.png

    相关文章

      网友评论

          本文标题:导航条leftBarButtonItem的问题修正

          本文链接:https://www.haomeiwen.com/subject/twandctx.html