Date
Dec. 22nd, 2024
 
2024年 11月 22日

Post: iOS: UIAlertController text alignment

iOS: UIAlertController text alignment

Published 12:07 Jul 10, 2016.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

Custom text alignment of UIAlertController:

let controller = UIAlertController(title: t, message: informative, preferredStyle: type)

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = alignment
paragraphStyle.lineBreakMode = lineBreakMode

let messageText = NSMutableAttributedString(string: info, attributes: [
  NSParagraphStyleAttributeName: paragraphStyle,
  NSFontAttributeName: font ?? UIFont.systemFont(ofSize: 12),
  NSForegroundColorAttributeName: textColor ?? UIColor.darkGray
  ])
controller.setValue(messageText, forKey: "attributedMessage")
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询