我正在尝试创建一个带有2个具有默认文本颜色的操作按钮的UIAlertController。这是代码:
let refreshAlert = UIAlertController(title: "", message: msg, preferredStyle: .alert)
refreshAlert.addAction(UIAlertAction(title: "No", style: .cancel, handler: { (action: UIAlertAction!) in
//dont bug user for permission for some time
}))
refreshAlert.addAction(UIAlertAction(title: "Notify me", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
center.requestAuthorization(options: [.badge, .carPlay, .alert, .sound]) { (granted, error) in
print("Granted: \(granted), Error: \(error)")
}
UIApplication.shared.registerForRemoteNotifications()
}))
但我得到以下输出:
为什么动作按钮的颜色为浅灰色?
答案 0 :(得分:0)
代码中是否有与此类似的行:
UIView.appearance().tintColor = .gray
设置视图的色调颜色似乎会影响按钮的颜色。您需要删除该行或根据需要进行调整。
也许考虑使用appearance(whenContainedInInstancesOf:)
方法。
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(colorLiteralRed: 0/255.0, green: 122/255.0, blue: 255/255.0, alpha: 1.0)