1

Alert (type actionSheet) message font, colour is not getting set by setting the attributedMessage.

actionSheet seperator lines are not visible

size of the actionSheet is increased, causing the popover size also to increase

func processActionSheet(message: String, actions: [UIAlertAction]) {

    let alertController = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
    alertController.modalPresentationCapturesStatusBarAppearance = true

    alertController.view.tintColor = UIColor.whiteColor
    alertController.setValue(NSAttributedString(string: message, attributes: [NSAttributedString.Key.foregroundColor: UIColor.white.colorWithAlpha(0.6), NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .callout)]), forKey: "attributedMessage")
    alertController.view.layer.borderWidth = 1
    alertController.view.layer.borderColor = UIColor.popoverDefaultBackgroundColor.cgColor
    alertController.view.layer.cornerRadius = 12
    if let subview = alertController.view.subviews.first, let alertContentView = subview.subviews.first {
        for innerView in alertContentView.subviews {
            innerView.backgroundColor = UIColor.popoverDefaultBackgroundColor
        }
    }

    for action in actions {
        alertController.addAction(action)
    }

    shouldDismissPopover = false
    self.present(alertController, animated: true)
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • This is a "hack". It's stated in the doc: "The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified." It wasn't reliable before because Apple could change its behaviour. It seems that Apple changed it in iOS13. Do you still want to use undocumented features or use a custom one? – Larme Sep 16 '19 at 09:19
  • The existing app user experience would change if we fall back to the default behaviour. I wanted to know if we could get an alternate to custom the appearance of actionSheet. – Greeshma Arunkumar Sep 16 '19 at 09:35

1 Answers1

0

you can change tint color after present alertController, it work

{
...
self.present(alertController, animated: true)
alertController.view.tintColor = UIColor.whiteColor
}

so, you can try change other attrib after present///