-1

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.

Acedia
  • 1
  • you should keep in mind what is said in the docs: https://developer.apple.com/documentation/uikit/uialertcontroller#1968629 –  Nov 05 '18 at 09:29
  • 2
    Hey & welcome to StackOverflow. Your question is too broad and doesn't make clear what exactly you're asking about and where you're stuck. Please see [How to ask](https://stackoverflow.com/help/how-to-ask) and update your question accordingly. – LinusGeffarth Nov 05 '18 at 09:30
  • @LinusGeffarth Sorry, I will read it later. – Acedia Nov 05 '18 at 09:45

2 Answers2

0
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..

0

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

Natarajan
  • 3,241
  • 3
  • 17
  • 34