导航条leftBarButtonItem的问题修正

2019-08-07  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读