自定义 UINavigationBar 的 backBarButtonItem 样式(不显示文字并自定义图片)

  • 第一步:首先将返回按钮的图片设为自定义的图片
    UIImage *image = [UIImage imageNamed: @"ic_default_back"];
    UINavigationBar *navigationBar = self.navigationController.navigationBar;
    navigationBar.backIndicatorImage = image;
    navigationBar.backIndicatorTransitionMaskImage = image;
    navigationBar.tintColor = [UIColor color_0x262626];
  • 第二步:将放回按钮的文字设置到最小,并且让字体透明,这样就达到了隐藏返回按钮文字的效果
UIBarButtonItem *item = [UIBarButtonItem appearance];
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:0.001],
                                 NSForegroundColorAttributeName: [UIColor clearColor]};
[item setTitleTextAttributes: attributes
                        forState: UIControlStateNormal];

多说一句: [UIBarButtonItem appearance] 这个会修改所有 UIBarButtonItem 的样式,所以请做其它处理。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容