更改UIActionSheet标题字符串的字体类型和大小 [英] Change font type and size of UIActionSheet title string

查看:96
本文介绍了更改UIActionSheet标题字符串的字体类型和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标题字符串为DO:这些任务的UIActionSheet。在标题字符串中,子字符串DO:应为Bold(具有特定字体大小),子字符串These tasks应为Regular。可能吗?我怎么能这样做?

I have a UIActionSheet with title string "DO: These tasks". In the title string, the substring "DO:" should be Bold(with a particular font size) and the substring "These tasks" should be Regular. Is it possible? How can I do this?

推荐答案

我假设你有一个实现 UIActionSheetDelegate 协议和你的类是当前 UIActionSheet 的委托类,所以在那个类中你可以改变<的整个标题code> UIActionSheet 喜欢

I assume you have a class which implements the UIActionSheetDelegate protocol and your class is a delegate class of the current UIActionSheet, so in that class you can change the whole title of the UIActionSheet like

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    for (UIView *_currentView in actionSheet.subviews) {
        if ([_currentView isKindOfClass:[UILabel class]]) {
            [((UILabel *)_currentView) setFont:[UIFont boldSystemFontOfSize:15.f]];
        }
    }
}

但就你看来你没有机会格式化 UILabel 对象的文本属性的部分。

but as far as you see you have no chance to format the part of the UILabel object's text property.

您可以为操作表添加新的 UILabel 现在使用不同的字体,如果你想看到带有粗体 DO:字符串的文本......但是从这里开始限制只是你想象的,你可以格式化 UIActionSheet 此方法中的元素或 -didPresentActionSheet:方法中的元素。

you could add a new UILabel for your actionsheet now with a different font, if you want to see a text with the bolded DO: string... but from here the limit is you imagination only, you can format the UIActionSheet's elements in this method or inside the -didPresentActionSheet: method as well.

所以这个想法

我们实际上无法直接访问 UIAlertView 的子视图或 UIActionSheet 对象,因此此解决方案可能无法在iOS7环境中正常运行。

如果您在iO上遇到任何问题S7,请评论给我!谢谢。

if you have any issue with it on iOS7, please comment it to me! thank you.

我还没有找到任何解决办法直接做这样的事情在iOS8中新的 UIAlertController ,标题标签看起来在 UIAlertController 的整个视图层次结构中不可见,在它出现之前或之后都不可见。

I have not found any solution to do such thing directly with the new UIAlertController in iOS8, the title label looks to be not visible in the entire view-hierarchy of the UIAlertController, neither visible before it appears or even after.

注意:我还发现不禁止重叠/覆盖其内容,之后它出现在屏幕上。目前无法预测它是否可以在Beta上运行,或者它是否是AppStore安全的。

NOTE: I've also figured out that it is not forbidden to overlap/cover its content, after it appeared on the screen. currently it is impossible to predict that it will work over Beta or whether or not it is AppStore-safe.

注意:请耐心等待注意视图生命周期的日程安排,如果不在导航堆栈中,请不要尝试在视图中显示任何内容或查看控制器。

无论如何,这是一个 Swift 解决方案,我可以如何到达图层,我可以添加我的自定义视图。

anyway, here is a Swift solution how I could reach the layers and I could add my custom view to it.

let alertController: UIAlertController = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alertController, animated: true, completion: {
    let aboveBlurLayer: UIView = alertController.view.subviews[0] as UIView
    let belowBlurLayer: UIView = (aboveBlurLayer.subviews[0].subviews as Array<AnyObject>)[0] as UIView
    let customView: UIView = UIView(frame: aboveBlurLayer.bounds)
    customView.backgroundColor = UIColor.redColor()
    aboveBlurLayer.addSubview(customView)
    })

注意:将自定义内容添加到警报/操作表可能很有用,但如果以后它不起作用,我会更新我的答案。

这篇关于更改UIActionSheet标题字符串的字体类型和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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