How do i remove text from back button on navbar within Xcode?

后端 未结 8 1785
醉酒成梦
醉酒成梦 2021-02-09 05:49

I set an arrow custom image to navigation bar by adding the following code in app delegate, it works but now im looking to remove the text completely for back button.

         


        
相关标签:
8条回答
  • 2021-02-09 06:15

    Simply move the text vertically so far that it no longer appears. This can be done at app launch in your app delegate.

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 20.f) forBarMetrics:UIBarMetricsDefault];
    

    Normally this call is for tweaking the vertical text position which can vary depending on the font used. Here the text is moved far enough that it's no longer inside the Back button view, and so is clipped into non-existence.

    0 讨论(0)
  • 2021-02-09 06:15

    Perfect solution globally

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Normal)
        UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Highlighted)
    
        return true
    }
    
    0 讨论(0)
提交回复
热议问题