美文网首页
iOS13遇到问题集中

iOS13遇到问题集中

作者: FreshAlpha | 来源:发表于2019-10-14 14:03 被阅读0次

    1.左滑删除按钮消失问题,iOS13中层级结构发生变化。

    if (IS_iOSGREATERTHAN13) {

            for(UIView*subviewinself.tableView.subviews) {

                if([subviewisKindOfClass:NSClassFromString(@"_UITableViewCellSwipeContainerView")] && [subview.subviewscount] >=1) {

                    for(UIView*subview0insubview.subviews){

                        if([subview0isKindOfClass:NSClassFromString(@"UISwipeActionPullView")] && [subview0.subviewscount] >=1){

                            UIButton*deleteButton = subview0.subviews[0];

                            [selfconfigDeleteButton:deleteButton];

                        }

                    }

                }

            }

        }

    2.Access to UITextField's _placeholderLabel ivar is prohibited。

    UITextFiled  "_placeholderLabel"设置属性font等崩溃问题,解决方案:使用swizzle

    extension NSObject {

        funcgetIvar(name:String) ->Any? {

            guard let_var =class_getInstanceVariable(type(of:self), name)else{

                returnnil

            }

            returnobject_getIvar(self, _var)

        }

    }

    extension UITextField {

        varplaceholderLabel:UILabel? {

            get{

                returngetIvar(name:"_placeholderLabel")as?UILabel

            }

        }

    }

    swizzle也操作了私有属性,对于苹果来说还是违背了它的意志,虽然现在没有bug,不保证未来不遇到类似 "_placeholderLabel"崩溃问题。另外一种温和的方案是设置attributedPlaceholder。

    extension UITextField {

        @objc func setPlaceholderColor(_ color: UIColor) {

            letplaceholderString =  NSAttributedString(string:self.placeholder??"", attributes: [NSAttributedString.Key.foregroundColor: color])

            self.attributedPlaceholder= placeholderString

        }

        @objcfuncsetPlaceholderAttribute(color:UIColor, font:UIFont) {

            letplaceholderString =  NSAttributedString(string:self.placeholder??"", attributes: [NSAttributedString.Key.foregroundColor: color,NSAttributedString.Key.font: font])

            self.attributedPlaceholder= placeholderString

        }

    }

    3.未开发暗黑模式之前,先不适配暗黑模式。

    全局关闭暗黑模式:

    在 Info.plist 文件中,添加 key 为 User Interface Style,类型为 String,value 设置为 Light 即可。

    相关文章

      网友评论

          本文标题:iOS13遇到问题集中

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