UIActionSheet / UIAlertController多行文本
这是我写的代码来显示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
但无法设置多行文本。 怎么做到这一点?
这似乎适用于iOS 10和Swift 3.1:
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 2
标准的UIAlertController
或UIAlertView
无法做到这一点。 我建议你缩短它。 你为什么不发出警报并输入这样的东西:
是否要仅为此实例或本系列中的所有活动更新响应。
答案是这些:
- 只有这个例子
- 所有活动
在iOS 10中:
如果要将其应用于所有UIAlertController,可以使用以下代码行:
[[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setNumberOfLines:2]; [[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setFont:[UIFont systemFontOfSize:9.0]];
把它放在AppDelegate的didFinishLaunchingWithOptions方法中。
尝试这个
let alert = UIAlertController(title: title, message: "you message go here", preferredStyle: UIAlertControllerStyle.alert) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) alert.addAction(cancelAction) self.present(alert, animated: true, completion: nil) UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 0 UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).lineBreakMode = .byWordWrapping