Remove text from Back button keeping the icon

前端 未结 29 2644
栀梦
栀梦 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:16

    Sometimes its not working to change only the title color, in case when the title is long. Because it might shift the navigation bar title to the left. So to prevent it you might need to shift the bar button title horizontally in addition to make it transparent:

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

提交回复
热议问题