使用Swift中的UIAlertController更改警报的标题和消息字体

编程入门 行业动态 更新时间:2024-10-27 23:23:01
本文介绍了使用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更改警报的标题和消息字体

本文发布于:2023-11-27 19:31:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   字体   消息   标题   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!