Custom back button in UINavigationController

前端 未结 10 1840
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 16:59

For an application I\'m developing, I need to display a custom back button in a navigation bar. I have the button asset as a PNG image, and I\'m writing this code:



        
10条回答
  •  萌比男神i
    2020-12-28 17:57

    Simply create a UIBarButtonItem instead of an embedded UIButton in UIBarButtonItem. Works fine!

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"button_back.png"] style:UIBarButtonItemStyleBordered target:nil action:nil];
    
    self.navigationItem.backBarButtonItem = backButton; 
    

提交回复
热议问题