I had been using following code to change text color of items which I add in UIActionSheet
.:
- (void)willPresentActionSheet:(UIActionSheet *)act
I have same task and I've made this hack today, dirty, but it works
class CustomAlertViewController: UIAlertController {
internal var cancelText: String?
private var font: UIFont? = UIFont(name: "MuseoSansCyrl-500", size: 12)
override func viewDidLoad() {
super.viewDidLoad()
self.view.tintColor = UIColor.blackColor()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.findLabel(self.view) //if you need ios 9 only, this can be made in viewWillAppear
}
func findLabel(scanView: UIView!) {
if (scanView.subviews.count > 0) {
for subview in scanView.subviews {
if let label: UILabel = subview as? UILabel {
if (self.cancelText != nil && label.text == self.cancelText!) {
dispatch_async(dispatch_get_main_queue(),{
label.textColor = UIColor.redColor() //for ios 8.x
label.tintColor = UIColor.redColor() //for ios 9.x
})
}
if (self.font != nil) {
label.font = self.font
}
}
self.findLabel(subview)
}
}
}
}
Swift 4
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .alert)
alert.view.tintColor = UIColor.black
self.present(alert, animated: true, completion: nil)
Ok, I ran into the same problem but I think I have found a solution:
The appropriate way should be like this and I guess it works in iOS7:
[[UIButton appearanceWhenContainedIn:[UIActionSheet class], nil] setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
But it will not work in iOS8 due to the fact that the ActionSheets "buttons" is now based on a UICollectionView. So after some digging around I got this to work instead:
[[UICollectionView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor blueColor]];