iOS 13 适配

1、UIViewController切换方式modalPresentationStyle

iOS13默认UIModalPresentationAutomatic模式,不符合我们的需求。改回之前的模式要用UIModalPresentationFullScreen。

vc.modalPresentationStyle = UIModalPresentationFullScreen;

但是,问题来了,项目里vc太多,而且因为接入了多家SDK,viewController并没有一个相同父VC,全局改太费劲了。

解决方案:

在appDelegate中实现了ViewController的分类,改变了modalPresentationStyle的值完美解决。

@implementation UIViewController(modalPresentationStyle)
 
- (UIModalPresentationStyle)modalPresentationStyle{
 
    return UIModalPresentationFullScreen;
 
}
@end

 


 2、"NSGenericException" - reason: "Access to UITextField's _placeholderLabel ivar is prohibited. This is an application bug"

设置TextFiled的默认文字颜色在iOS13 Crash。

[textfield setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
 查了一下,帖子挺多的,解决方案:

Ivar ivar =  class_getInstanceVariable([UITextField class], "_placeholderLabel");
UILabel *placeholderLabel = object_getIvar(textField, ivar);
placeholderLabel.textColor = [UIColor whiteColor];
记得加头文件

#import <objc/runtime.h> 

 

3、去除TabBar黑线

iOS13 新增api  UITabBarAppearance

if (@available(iOS 13.0, *)) {//去除iOS13的TabBarg黑线

        UITabBarAppearance* tabbarAppearance =self.tabBar.standardAppearance;

        tabbarAppearance.backgroundImage = [self imageWithColor:[UIColor clearColor] size:self.tabBar.size];

        tabbarAppearance.shadowImage = [self imageWithColor:[UIColor clearColor] size:self.tabBar.size];

        self.tabBar.standardAppearance = tabbarAppearance;

    } else {

        self.tabBar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:self.tabBar.size];

        self.tabBar.shadowImage = [self imageWithColor:[UIColor clearColor] size:self.tabBar.size];

    }

注: [self imageWithColor:[UIColor clearColor] size:self.tabBar.size]; 为根据控件size生成的纯色图片,代码如下

#pragma mark - 给出颜色值,制作纯色图片

- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {

    if (!color || size.width <=0 || size.height <=0) return nil;

    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);

    UIGraphicsBeginImageContextWithOptions(rect.size,NO, 0);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, color.CGColor);

    CGContextFillRect(context, rect);

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值