美文网首页
H5 调用系统相册没有取消按钮

H5 调用系统相册没有取消按钮

作者: Funnyer | 来源:发表于2019-07-19 16:10 被阅读0次

    今天测试发现一个问题,H5 调用系统相册右上角没有取消按钮,但是点击右上角应该有取消按钮的地方,可以pop 回去。

    我当时的想法是:

    肯定是H5 调用系统相册的时候,有一些属性没有设置,导致取消按钮的颜色是透明,因为我既不知道H5 何时调用系统相册,更不会加以控制,肯定不是我的原因。

    但是转念一想:

    H5 调用的系统原生相册,看不到取消按钮是不是和我对导航栏的设置有关系呢?

    带着这个疑问,看一下我对于导航栏的设置:

    UIBarButtonItem.appearance().setTitleTextAttributes([
                NSAttributedString.Key.foregroundColor: UIColor.clear
                ], for: .normal)
    UIBarButtonItem.appearance().setTitleTextAttributes([
                NSAttributedString.Key.foregroundColor: UIColor.clear
                ], for: .highlighted)
    

    很明显,设置UIBarButtonItem 按钮为透明,当时的目的是只显示系统的返回图标,不显示返回文字,所以把文字设置为透明色。

    但是H5 调用系统相册显示的取消按钮就是系统的,自然就被我设置成透明色了。

    所以应该针对UIImagePickerController 设置一下UIBarButtonItem 的颜色:

    let naviAppearance = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UIImagePickerController.self])
            naviAppearance.setTitleTextAttributes([
                NSAttributedString.Key.foregroundColor: UIColor(gray: 51)
                ], for: .normal)
    naviAppearance.setTitleTextAttributes([
                NSAttributedString.Key.foregroundColor: UIColor(gray: 51, alpha: 0.6)
                ], for: .highlighted)
    

    相关文章

      网友评论

          本文标题:H5 调用系统相册没有取消按钮

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