UIActionSheet / UIAlertController多行文本 [英] UIActionSheet/UIAlertController multiline text

查看:347
本文介绍了UIActionSheet / UIAlertController多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我写的代码,用于显示 UIActionSheet

This is the code I am writing to display UIActionSheet.

actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"updateresponseforrecurring", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:
                   NSLocalizedString(@"updateresponseonlyforthis", nil),
                   NSLocalizedString(@"updateresponseforallactivities", nil),
                   nil];
    actionSheet.tag = 2;
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow];  

这是我得到的:

显然,第二个选项较长,因此尺寸变小以适应宽度。

但我希望所有选项都使用相同的字体大小,这样我就可以使用多行。还尝试使用 UIAlertController ,但无法设置多行文字。
如何实现这一目标?

Clearly, second option is longer and thus the size gets smaller to accommodate the width.
But I want the same font size for all the options which leaves me with multiline. Also tried with UIAlertController but not able to set multiline text. How to achieve this ?

推荐答案

这似乎适用于iOS 10和Swift 3.1:

This seems to work in iOS 10 and Swift 3.1:

UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 2

这篇关于UIActionSheet / UIAlertController多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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