iOS 适配

1,311 阅读1分钟

tableView/collectionView偏移问题

Swift版本
Objective-C版本
    if (@available(iOS 11.0, *)) {
        self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
Swift版本
         if #available(iOS 11.0, *) {
            self.tableView.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }

WKWebView设置全屏

Swift版本

Objective-C版本

        if (@available(iOS 11.0, *)) {
            self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        // 自定导航栏颜色
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
        self.navigationController.navigationBar.tintColor = [UIColor blackColor];
        // 导航栏透明并取消分隔线
        [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setShadowImage:[UIImage new]];
        // 透明
        self.navigationController.navigationBar.translucent = YES;

iOS黑暗模式

if (@available(iOS 13.0, *)) {
        self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    } else {
        
    }

仿抖音tabbar透明

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.tabBarController?.tabBar.barTintColor = UIColor.clear;
        self.tabBarController?.tabBar.backgroundColor = UIColor.clear;
        self.tabBarController?.tabBar.backgroundImage = UIImage(color: UIColor.clear);
        self.tabBarController?.tabBar.shadowImage = UIImage(color: UIColor.clear);
        self.tabBarController?.tabBar.isTranslucent = true;
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.tabBarController?.tabBar.barTintColor = UIColor.white;
        self.tabBarController?.tabBar.backgroundColor = UIColor.white;
        self.tabBarController?.tabBar.backgroundImage = nil;
        self.tabBarController?.tabBar.shadowImage = nil;
    }