UIActionSheet/UIAlertController multiline text

前提是你 提交于 2019-12-01 04:48:15

问题


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];  

This is what I get using this :

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 ?


回答1:


This seems to work in iOS 10 and Swift 3.1:

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



回答2:


This is not possible with the standard UIAlertController or UIAlertView. I would recommend you to make it shorter. Why don't you make an alert and type something like this:

Do you want to update the response only for this instance or for all activities in this series.

The answers would be these:

  • Only this instance
  • All activities



回答3:


In iOS 10:

If you want to apply it to all UIAlertController, you can use these lines of code:

[[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setNumberOfLines:2];
[[UILabel appearanceWhenContainedIn:[UIAlertController class], nil] setFont:[UIFont systemFontOfSize:9.0]];

put this in didFinishLaunchingWithOptions method of the AppDelegate.




回答4:


try this

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


来源:https://stackoverflow.com/questions/33215654/uiactionsheet-uialertcontroller-multiline-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!