美文网首页
自定义 UINavigationBar 的 backBarBut

自定义 UINavigationBar 的 backBarBut

作者: 熊梓君 | 来源:发表于2017-08-18 16:08 被阅读81次
  • 第一步:首先将返回按钮的图片设为自定义的图片
    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 的样式,所以请做其它处理。

相关文章

网友评论

      本文标题:自定义 UINavigationBar 的 backBarBut

      本文链接:https://www.haomeiwen.com/subject/jduarxtx.html