iOS13的一些问题与总结

2019-11-06  本文已影响0人  生命不止运动不息
iOS13下会奔溃的一些操作。

1.访问私有属性 如

[textfield setValue:[UIColor colorWithRgb153] forKeyPath:@"_placeholderLabel.textColor"];
[textfield setValue:[UIFont systemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];

解决方案:使用textFiled的attributedPlaceholder属性进行holder设置以及字号等

2.使用系统的一些控件,通过投机取巧的方式,对其进行一些操作
如,对searchBar进行背景移除,ios13 之前没毛病,ios13开始莫名崩溃。原因就是如此。以下代码ios13后不可使用。

//移除背景
        for (UIView *view in _searchBar.subviews) {
            // for later iOS7.0(include)
            if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
                _searchBarBgView =
                [view.subviews objectAtIndex:0];
                [view.subviews objectAtIndex:0].backgroundColor = [UIColor clearColor];
                [[view.subviews objectAtIndex:0] removeFromSuperview];
                break;
            }
        }

总结

不要对系统的东西,耍些小聪明,苹果爸爸分分钟让你吃不了兜着走啊。
写控件,还是应该考虑自己封装。

上一篇 下一篇

猜你喜欢

热点阅读