使用Swift中的UIAlertController更改警报的标题和消息字体 [英] Change title and message font of alert using UIAlertController in Swift

查看:207
本文介绍了使用Swift中的UIAlertController更改警报的标题和消息字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改使用UIAlertController显示的警报的标题和消息字体
我正在尝试使用NSAttributedStirng,但是它给编译器错误,即无法使用NSAttributed字符串而不是Stirng
我尝试过与这个类似的东西

I am trying to change the title and message font for an alert shown using UIAlertController I am trying to do using an NSAttributedStirng, but it gives compiler error that a NSAttributed string cannot be taken instead of Stirng I tried something similar to this

var title_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_MEDIUM_16]
var msg_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_REGULAR_14]
var title = NSMutableAttributedString(string:"Done", attributes:title_attrs)

var msg = NSMutableAttributedString(string:"The job is done ", attributes:msg_attrs)
let alertController = UIAlertController(title: title, message: title , preferredStyle: UIAlertControllerStyle.Alert)

有人可以指导我如何实现这个目标吗?

Can someone guide me how can I achieve this?

推荐答案

我认为Apple删除了belongsTitle和 - 来自API的消息。它从来不是公众的一部分 API 因此,如果您使用它,Apple可能不允许您在应用商店中使用该应用。

I think Apple removed the attributedTitle and -message from the API. It was never part of the public API so it might be that Apple will not allow your app in the app store if you used it.

您应该使用UIAlertController作为是。如果您想稍微自定义一下,请参阅 NSHipster帖子。如果您想要更多控制,请创建要显示的自定义视图。

You should use the UIAlertController as is. If you want to customise it a bit see this NSHipster post. If you want more control, create a custom View to display.

这篇关于使用Swift中的UIAlertController更改警报的标题和消息字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆