IOS 13 新特性适配 Dark Mode

iOS 13 支持适配的机型
iPhone X、iPhone XR、iPhone XS、iPhone XS Max
iPhone 8、iPhone 8 Plus
iPhone 7、iPhone 7 Plus
iPhone 6s、iPhone 6s Plus
iPhone SE
iPod touch (第七代)

新特性适配 Dark Mode
iOS 13 推出暗黑模式,UIKit 提供新的系统颜色和 api 来适配不同颜色模式,xcassets 对素材适配也做了调整,具体适配可见: Implementing Dark Mode on iOS。

对一下几点做适配
1、通过attributedPlaceholder属性修改Placeholder颜色
IOS 13 新特性适配 Dark Mode_第1张图片

@interface UITextField (TextFeildPlaceholder)
/// 设置textfield placeholder
/// @param textFeild textFeild
/// @param placeholder  placeholder 文字
/// @param color placeholder 颜色
-(void)setTextFeild:(UITextField*)textFeild placeholder:(NSString* )placeholder andTextFliedColor:(UIColor *)foregroundColor;
@end

@implementation UITextField  (TextFeildPlaceholder)
-(void)setTextFeild:(UITextField*)textFeild placeholder:(NSString* )placeholder andTextFliedColor:(UIColor *)foregroundColor{
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:textFeild.font}];
           textFeild.attributedPlaceholder = attrString;
}
@end

//使用
   [self.personNameTX setTextFeild:self.personNameTX placeholder:@"请输入您的真实姓名" andTextFliedColor:kColorCCCCCC];

2.原生进入 WKWebView 页面出现黑色背景

 self.webView = [[WKWebVie
w alloc] initWithFrame:CGRectZero configuration:configuration];
  self.webView.scrollView.backgroundColor = [UIColor whiteColor];

3.cell 背景色 黑色修改为 白色,并取消点击效果
IOS 13 新特性适配 Dark Mode_第2张图片

        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
若设置系统选择状态,可直接设置cell的背景色
 	cell.backgroundColor = [UIColor whiteColor];

4.获取当前处于什么模式

if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
        [self.titleLabel setText:@"DarkMode"];
    }
    else {
        [self.titleLabel setText:@"LightMode"];
    }

5.设置UISearchBar 中的 UITextField 文字显示大小及颜色

[self setAppearance];

- (void)setAppearance
{
    [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]]
     setDefaultTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor blackColor]}];
}

6.pickView 颜色出现文字展现不出
IOS 13 新特性适配 Dark Mode_第3张图片

 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
     if ([self.delegate respondsToSelector:@selector(pickerView:attributedTitleForRow:forComponent:)]) {
         return [self.delegate pickerView:self attributedTitleForRow:row forComponent:component];
     }  
else if([self.delegate respondsToSelector:@selector(pickerView:titleForRow:forComponent:)]) {
        NSString *title =  [self.delegate pickerView:self titleForRow:row forComponent:component];
       NSAttributedString *att = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
        return att;
  	}
  	return nil;
 }

7.设置系统导航栏

   if (@available(iOS 13.0, *))
    {
        if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) 获取当前处于什么模式
        {
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
        }else
        {
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        }
    }
    else
    {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }

8.所有UILabel,UIButton 显示文字都需要设置展示颜色

self.titleLab.textColor = kColor34373A;

你可能感兴趣的:(项目优化)