Remove text from Back button keeping the icon

前端 未结 29 2691
栀梦
栀梦 2020-11-28 23:26

I want to remove the text from the back button, but I want to keep the icon. I have tried

let backButton = UIBarButtonItem(title: \"\", style: UIBarButtonIt         


        
29条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 00:12

    For Swift 4+ put these lines into AppDelegate at didFinishLaunchingWithOptions

    let BarButtonItemAppearance = UIBarButtonItem.appearance()
    
    BarButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)      
    BarButtonItemAppearance.setBackButtonTitlePositionAdjustment(UIOffsetMake(-200, 0), for:UIBarMetrics.default)
    

提交回复
热议问题