OStack程序员社区-中国程序员成长平台

标题: ios - 在导航项中隐藏返回文本 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:34
标题: ios - 在导航项中隐藏返回文本

我需要通过替换导航栏中的后退文本(按钮)来设置后退箭头。我可以查看后退箭头,但我不知道如何在导航项中隐藏后退文本。这是我的代码:

因此收到警告: : CGImageCreateWithImageProvider: invalid image size: 0 x 0.

(void)viewWillAppearBOOL)animated
 {
    UIImage *backButtonHomeImage = [[UIImage imageNamed"back-arrow.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 104, 13)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonHomeImage  forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    self.navigationItem.leftBarButtonItem = nil;
}



Best Answer-推荐答案


答案

    -(void)viewWillAppearBOOL)animated
     {
        [super viewWillAppear:animated];
        if([self.navigationController.viewControllers objectAtIndex:0] != self)
        {
            UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
            [backButton setImage:[UIImage imageNamed"back-arrow.png"] forState:UIControlStateNormal];
            [backButton setShowsTouchWhenHighlighted:TRUE];
            [backButton addTarget:self actionselector(popViewControllerWithAnimation) forControlEvents:UIControlEventTouchDown];
            UIBarButtonItem *barBackItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
            self.navigationItem.hidesBackButton = TRUE;
            self.navigationItem.leftBarButtonItem = barBackItem;
        }
}

-(void)popViewControllerWithAnimation
{  
   [self.navigationController popViewControllerAnimated:YES];

}

可能会有所帮助。

关于ios - 在导航项中隐藏返回文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20216723/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4