iOS UI

iOS13 App适配

2019-10-18  本文已影响0人  修正

1. 设置不响应黑暗模式

Info.plist中添加以下代码

    <key>UIUserInterfaceStyle</key>
    <string>Light</string>
Info.plist

2. 字体适配

iOS13中获取系统字体的fontName,得到的是并没有什么用的 romannewtime字体.
建议使用

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight API_AVAILABLE(ios(8.2));

// Suggested values for use with UIFontWeightTrait, and UIFont's systemFontOfSize:weight:
// Beware that most fonts will _not_ have variants available in all these weights!
UIKIT_EXTERN const UIFontWeight UIFontWeightUltraLight API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightThin API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightLight API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightRegular API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightMedium API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightSemibold API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightBold API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightHeavy API_AVAILABLE(ios(8.2));
UIKIT_EXTERN const UIFontWeight UIFontWeightBlack API_AVAILABLE(ios(8.2));

3. 弹出样式

/*
 Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
 If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but system-provided subclasses may resolve UIModalPresentationAutomatic to other concrete presentation styles. Participation in the resolution of UIModalPresentationAutomatic is reserved for system-provided view controllers.
 Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
 */
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));

因此我们的方案是在BaseViewController中,指定样式为全屏,两个时机:

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationFullScreen;
    }
    return self;
}

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^ __nullable)(void))completion {
    if (@available(iOS 13.0, *)) {
        if (viewControllerToPresent.modalPresentationStyle == UIModalPresentationPageSheet) {
            viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
        }
    }

    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}

4. UITabBar样式

//iOS 13中需设置
if (@available(iOS 13.0, *)) {
    self.tabBar.tintColor = Red_COLOR;
    self.tabBar.unselectedItemTintColor = 66_66_66_COLOR;
}
// 需要将gif的每一帧设置为 UIImageRenderingModeAlwaysOriginal 
    if (@available(iOS 13.0, *)) {
        NSArray *sourceInsideImages = [tabImage images];
        NSMutableArray *insideImages = [[NSMutableArray alloc] initWithCapacity:0];
        for (UIImage *sourceImage in sourceInsideImages) {
            UIImage *insideImage = [sourceImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            [insideImages addObject:insideImage];
        }
        tabImage = [UIImage animatedImageWithImages:insideImages duration:tabImage.duration];
    }
        UITabBarAppearance *appearance = tabBar.standardAppearance.copy;
        appearance.shadowColor = [UIColor clearColor];
        appearance.shadowImage = [UIImage new];
        tabBar.standardAppearance = appearance;
上一篇 下一篇

猜你喜欢

热点阅读