Date
Sep. 9th, 2024
 
2024年 8月 7日

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.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系