其他分享
首页 > 其他分享> > iOS 13适配深色模式【设置UITabBarItem上title颜色& 适配第三方库QMUIKit在iOS13的问题】

iOS 13适配深色模式【设置UITabBarItem上title颜色& 适配第三方库QMUIKit在iOS13的问题】

作者:互联网

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

前言 I、设置UITabBarItem上title颜色
        self.tabBar.unselectedItemTintColor = ktabNorTextColor;

self.tabBar.tintColor = ktabSelectedTextColor;


1.1 适配代码

    // 适配iOS13导致的bug
if (@available(iOS 13.0, *)) {
// iOS 13以上
// self.tabBar.tintColor = ;
self.tabBar.unselectedItemTintColor = ktabNorTextColor;

self.tabBar.tintColor = ktabSelectedTextColor;
// self.tabBar.unselectedItemTintColor = ;

// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffse/tMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
} else {
// // iOS 13以下
// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffsetMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0x999999)} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0xfb5400)} forState:UIControlStateSelected];
//设置文字样式
NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
textAttr[NSForegroundColorAttributeName] = ktabNorTextColor;
[childVC.tabBarItem setTitleTextAttributes:textAttr forState:UIControlStateNormal];
//选择状态的文字颜色样式
NSMutableDictionary *selectedTextAttr = [NSMutableDictionary dictionary];
[selectedTextAttr setValue:ktabSelectedTextColor forKey:NSForegroundColorAttributeName];



[childVC.tabBarItem setTitleTextAttributes:selectedTextAttr forState:UIControlStateSelected];



}


  II 、适配第三方库QMUIKit在iOS13的问题

适配第三方库QMUIKit在iOS13的问题【 -[_UINavigationBarContentView setDirectionalLayoutMargins:],】“KVC访问私有属性”

升级Xcode之后,今天在iOS13中打开app的时候闪退,错误信息是*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Client error attempting to change layout margins of a private view'

*** Assertion failure in -[_UINavigationBarContentView setDirectionalLayoutMargins:]

-> Installing QMUIKit 4.0.4 (was 3.2.1 and source changed to `https://cdn.cocoapods.org/` from `https://github.com/cocoapods/specs.git`)
$ /usr/bin/git ls-remote https://github.com/Tencent/QMUI_iOS.git master
2416a78cac2b447e8895e1260b2547f1764240c0 refs/heads/master
> Git download
> Git download
$ /usr/bin/git clone https://github.com/Tencent/QMUI_iOS.git /var/folders/6t/z1p2xgls4wz_pw36r58hhspr0000gn/T/d20200212-45583-1mewkqz --template= --single-branch --depth 1
--branch master
Cloning into '/var/folders/6t/z1p2xgls4wz_pw36r58hhspr0000gn/T/d20200212-45583-1mewkqz'...

III、see also iOS13适配指南:1、present半屏问题2、禁止 KVC访问UI控件私有API 3、 深色模式

 

标签:13,UITabBarItem,title,适配,iOS,iOS13,item,setTitleTextAttributes
来源: https://blog.51cto.com/iosre/2963819