Search code examples
objective-cuiactionsheet

set font size to UIActionSheet title


I need to set size UIActionSheet title "Select option to Copy"

enter image description here

with this code :

  [[UIActionSheet alloc] initWithTitle:@"Select option to copy:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                     otherButtonTitles:@"copy all ",nil];

Solution

  • You could take advantage of Runtime Properties to set the font. By using NSAttributedString you can achieve this.

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                         otherButtonTitles:@"copy all ",nil];
    
    //Creating Attributed String with System Font size of 30.0f
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Select option to copy:" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:30.0f]}];
    
    //Accessing the Alert View Controller property from Action Sheet
    UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
    
    //Setting Attributed Title property of Alert View Controller
    [alertController setValue:attrString forKey:@"_attributedTitle"];
    
    //Displaying the Action Sheet
    [actionSheet showInView:self.view];
    

    enter image description here