Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何设置只带图片,右边不带文字的返回按钮,我设置title为空之后,但是自己的图片位置偏左 #184

Open
PengJiang520 opened this issue Sep 5, 2023 · 3 comments

Comments

@PengJiang520
Copy link

代码

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupSubviews];
    // self.hbd_barShadowHidden = YES;
    // self.hbd_barTintColor = [UIColor whiteColor];
    self.hbd_barAlpha = 0.0;
    self.hbd_barStyle = UIBarStyleBlack;
    self.hbd_tintColor = UIColor.whiteColor;
    self.hbd_barShadowHidden = YES;
    self.title = @"";

}

@listenzz
Copy link
Owner

listenzz commented Sep 5, 2023

这是个普遍问题,请搜索其它资料解决。通常有 runtime,BaseViewController 等方法。

@PengJiang520
Copy link
Author

我在baseViewController 实现了此处代码,但是侧滑的手势没有响应
// TODO: 当前控制器最前面的一个不存在返回的按钮.
if (self.navigationController.viewControllers.count > 1) {
UIImage *leftImageName = [UIImage imageNamed:@"iv_hvac_back"];
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setFrame:CGRectMake(0, 0, leftImageName.size.width, 40)];
[backBtn setImage:leftImageName forState:UIControlStateNormal];
[backBtn setImage:leftImageName forState:UIControlStateHighlighted];
[backBtn setShowsTouchWhenHighlighted:NO];
[backBtn addTarget:self action:@selector(pb_backToPreviousViewController) forControlEvents:UIControlEventTouchUpInside];
if (ios11_0){
[backBtn setFrame:CGRectMake(0, 0, 40, 40)];
backBtn.contentEdgeInsets=UIEdgeInsetsMake(0, 0, 0, 10);
}
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = item;
}

  • (void)pb_backToPreviousViewController {
    if (self.navigationController.presentingViewController){
    [self dismissViewControllerAnimated:YES completion:nil];
    }else{
    [self.navigationController popViewControllerAnimated:YES];
    }
    }

@zhwIdea
Copy link

zhwIdea commented Nov 27, 2023

在viewDidLoad中实现:self.navigationController.navigationBar.topItem.title = @"";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants