UISegmentedControl
默认样式改变(UI有要求,务必优化)
iOS13以上对于通用的仅颜色UI的变更,可以通过创建子类来做覆盖,设置一个自定义tintColor 替代。
- (void)setDividerImage:(nullable UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
- (void)setTitleTextAttributes:(nullable NSDictionary *)attributes forState:(UIControlState)state API_AVAILABLE(ios(5.0)) UI_APPEARANCE_SELECTOR;
可以通过这三个方法设置纯色图片来还原之前的样式。
Dark Mode
若不想支持深夜模式 ,只需要在Info.plist下 新增键User Interface Style 值为Light即可。
模态弹出默认交互改变
ios13新增了一个UIModalPresentationAutomatic,系统会默认UIModalPresentationStyle 为UIModalPresentationAutomatic ,并且模态推出现在默认会get到UIModalPresentationPageSheet,通过运行时新写一个get方法与系统方法交互,并且将``UIModalPresentationPageSheet改为UIModalPresentationFullScreen即可,比较暴力,如果有指定UIModalPresentationPageSheet`的可以通过额外属性区分。
// Xcode11+ iOS13兼容扩展 适配modalPresentationStyle导致的问题
Method systemGetModalPresentationStyle = class_getInstanceMethod(self.class, @selector(modalPresentationStyle));
Method ccGetModalPresentationStyle = class_getInstanceMethod(self.class, @selector(cc_modalPresentationStyle));
if (!class_addMethod(self.class, @selector(modalPresentationStyle), method_getImplementation(systemGetModalPresentationStyle), method_getTypeEncoding(systemGetModalPresentationStyle))) {
method_exchangeImplementations(systemGetModalPresentationStyle, ccGetModalPresentationStyle);
}
- (UIModalPresentationStyle)cc_modalPresentationStyle{
UIModalPresentationStyle modalPresentationStyle = [self cc_modalPresentationStyle];
if (modalPresentationStyle == (UIModalPresentationStyle)-2) {
modalPresentationStyle = UIModalPresentationFullScreen;
}
if (modalPresentationStyle == UIModalPresentationPageSheet){
modalPresentationStyle = UIModalPresentationFullScreen;
}
return modalPresentationStyle;
}
私有方法KVC 不允许使用
目前发现的有如下几种
UITextField的valueForKey:@"_placeholderLabel.textColor"
使用attributedPlaceholder替代,可以使用子类或者扩展来优化
UISearchBar的valueForKey:@"_searchField"
UITextField *searchField;
if ([UIDevice currentDevice].systemVersion.floatValue > 12.3) {
searchField = searchBar.searchTextField;
}else{
searchField = [searchBar valueForKey:@"_searchField"];
}
[[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
可以在基类下使用View来替代设置StatusBar的背景颜色。
UIStatusBarStyle
iOS以上 UIStatusBarStyleDefault 会跟随系统深夜模式自动变化,如果不支持深夜模式的App可以通过宏调整
MPMoviePlayerController
使用AVKit替换即可
LaunchImage
要求使用LaunchScreen.storyboard ,删除LaunchImage.assets,新建LaunchScreenImage,修改Content.json 如下,设置对应大小图片,在StoryBoard新建ImageView设置约束,若需要满屏,调整不遵守安全间距即可
{
"images" : [
{
"idiom" : "iphone",
"scale" : "1x"
},
{
"idiom" : "iphone",
"scale" : "2x"
},
{
"idiom" : "iphone",
"filename" : "Default-736.png",
"scale" : "3x"
},
{
"idiom" : "iphone",
"subtype" : "retina4",
"scale" : "1x"
},
{
"idiom" : "iphone",
"filename" : "Default-568.png",
"subtype" : "retina4",
"scale" : "2x"
},
{
"idiom" : "iphone",
"subtype" : "retina4",
"scale" : "3x"
},
{
"idiom" : "iphone",
"filename" : "Default-736.png",
"subtype" : "736h",
"scale" : "3x"
},
{
"idiom" : "iphone",
"filename" : "Default-667.png",
"subtype" : "667h",
"scale" : "2x"
},
{
"idiom" : "iphone",
"filename" : "Default-812.png",
"subtype" : "2436h",
"scale" : "3x"
},
{
"idiom" : "iphone",
"filename" : "Default-1242.png",
"subtype" : "2688h",
"scale" : "3x"
},
{
"idiom" : "iphone",
"filename" : "Default-828.png",
"subtype" : "1792h",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
UITextField 设置LeftView及RightView
iOS13 在设置左右视图是UIImageView的时候,需要在UIImageView 外层包裹一次UIView视图,才能保证想要的间距效果。可以通过交互方法重写Set LeftView与RightView,在外层包裹UIView,并赋值相应Frame。若有特殊配置,可以通过判断视图类,做针对性包裹。
UISearchBar 黑线处理导致崩溃
NSClassFromString(@"UISearchBarBackground")
蓝牙权限需要申请
如果有蓝牙使用的App,需要设置权限获取
第三方SDK升级