I'm studing iOS, and I got a question. How should I do to add a detail label to UIAlertAction? Like UITableViewCell with UITableViewCellStyleSubtitle.
Thanks.
I'm studing iOS, and I got a question. How should I do to add a detail label to UIAlertAction? Like UITableViewCell with UITableViewCellStyleSubtitle.
Thanks.
let attributedString = NSAttributedString(string: "My Message",
attributes: [NSAttributedStringKey.font : UIFont(name: "Avenir-Light", size: 20)!])
let alert = UIAlertController(title: "Title", message: "", preferredStyle: .alert)
alert.setValue(attributedString, forKey: "attributedMessage")
let cancelAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
try this one..
You can not add detailedText(two labels) in UIAlertAction
. But Instead of that you can make your own customized alert view and action buttons. If you don't have time, you can search for third party libraries.
Also if UIAlertAction
has ability to set attributed text, you could append two lines(by adding "\n" in NSAttributedString
with small font to display like detailLabel) of text as UIAlertAction
title. But unfortunately there is no public API to set attributed String as UIAlertAction title. But there is a private API as mentioned in this answer UIAlertController custom font, size, color