缺少UIActivityViewController中的取消按钮文本

时间:2017-01-18 11:13:30

标签: ios swift uialertview

我有一个用Swift编写的iOS应用程序,而我的UIActivityViewController中的Cancel按钮缺少其文本。按钮是全白的。有什么想法吗?

func photoEditViewController(_ photoEditViewController: PhotoEditViewController, didSave image: UIImage, and data: Data) {

    let objectsToShare: [AnyObject] = [ image ]
    let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
    activityViewController.popoverPresentationController?.sourceView = self.window?.rootViewController?.view
    activityViewController.completionWithItemsHandler = { activity, success, items, error in
        if success {
            let alertController = UIAlertController(title: "Done", message: "Thanks for share!", preferredStyle: .alert)
            let okBtn = UIAlertAction(title: "OK", style: .default, handler: nil)
            alertController.addAction(okBtn)
            self.topMostController().present(alertController, animated: true, completion: nil)
        }
    }
    topMostController().present(activityViewController, animated: true, completion: { () in

    })

}


func topMostController() -> UIViewController {
    var topController: UIViewController = UIApplication.shared.keyWindow!.rootViewController!
    while (topController.presentedViewController != nil) {
        topController = topController.presentedViewController!
    }
    return topController
}

image here

3 个答案:

答案 0 :(得分:0)

您应该将“取消按钮”添加为单独的操作

let cancelBtn = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelBtn)

答案 1 :(得分:0)

你有没有设置

UIButton.appearance().tintColor = UIColor.white

这就是我的所作所为。

答案 2 :(得分:0)

[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateHighlighted];