iOS 9:调用UICollectionViewCell.appearance()

时间:2015-08-08 12:19:24

标签: uicollectionviewcell swift2 uialertcontroller uiappearance

说我想提出一个UIAlertController

import UIKit
class ViewController: UIViewController {
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let alert = UIAlertController(title: "Alert!", message: "Whoops.", preferredStyle: .Alert)
        let dismiss = UIAlertAction(title: "Go back.", style: .Default) { (_) in }
        alert.addAction(dismiss)
        self.presentViewController(alert, animated: true, completion: nil)
    }
}

在应用程序的其他地方,我有一个UICollectionView,我在我的UIAppearance中使用AppDelegate设置样式(最好遵循Mattt Thompson的建议) :

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UICollectionViewCell.appearance().backgroundColor = UIColor.blackColor()
    return true
}

这会使UIAlertAction按钮的背景变黑,这不是我想要的。

我尝试将iOS 9中的新appearanceWhenContainedInInstancesOfClasses功能用于restore the default styling ...

UICollectionViewCell.appearanceWhenContainedInInstancesOfClasses([UIAlertController.self]).backgroundColor = nil

...但这会在该行上出现EXC_BAD_ACCESS错误。

如何在不中断UICollectionViewCell.appearance()样式的情况下使用UIAlertController

0 个答案:

没有答案