Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 329
Nitish Avatar asked Oct 19 '15 13:10

Nitish


People also ask

Why should I use the uiactionsheet control instead of uialertcontroller?

As of iOS 8, app devs should use UIAlertController rather than this class. Extensions may not use this class at all. The UIActionSheet control is a convenient way to allow the application user to choose among alternative actions. The following code and diagram are taken from the "Action Sheets" section of the "iOS Standard Controls" sample.

What is the difference between UIAlertView and uialertcontroller?

UIAlertController replaces both UIAlertView and UIActionSheet, thereby unifying the concept of alerts across the system, whether presented modally or in a popover. Unlike the classes it replaces, UIAlertController is a subclass of UIViewController.

What is the use of uialertcontroller in Salesforce?

A UIAlertController object displays an alert message to the user. This class replaces the UIActionSheet and UIAlertView classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using the presentViewController:animated:completion: method.

Did you know UIAlertView and uiactionsheet are deprecated in iOS 8?

Did you know that UIAlertView and UIActionSheet (as well as their respective delegate protocols) are deprecated in iOS 8? It’s true. ⌘-click on UIAlertView or UIActionSheet in your code, and check out the top-level comment: UIAlertView is deprecated.


1 Answers

This seems to work in iOS 10 and Swift 3.1:

UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 2
like image 110
LenK Avatar answered Oct 04 '22 16:10

LenK