Search code examples
iosuiactionsheetuialertcontroller

UIActionSheet/UIAlertController multiline text


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 :

enter image description here

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 ?


Solution

  • This seems to work in iOS 10 and Swift 3.1:

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