Roei Nadam
Roei Nadam

Reputation: 1780

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

Upvotes: 1

Views: 4092

Answers (2)

Burhanuddin Sunelwala
Burhanuddin Sunelwala

Reputation: 5343

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

Upvotes: 3

Anshad Rasheed
Anshad Rasheed

Reputation: 2566

You can change the title font of uiactionsheet by using this delgate

  -(void)willPresentActionSheet:(UIActionSheet *)actionSheet {
        for (UIView *_currentView in actionSheet.subviews) {
            if ([_currentView isKindOfClass:[UILabel class]]) {
                UILabel *l = [[UILabel alloc] initWithFrame:_currentView.frame];
                l.text = [(UILabel *)_currentView text];
                [l setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
                l.textColor = [UIColor darkGrayColor];
                l.backgroundColor = [UIColor clearColor];
                [l sizeToFit];
                [l setCenter:CGPointMake(actionSheet.center.x, 25)];
                [l setFrame:CGRectIntegral(l.frame)];
                [actionSheet addSubview:l];
                _currentView.hidden = YES;
                break;
            }
        }
    }

Upvotes: 0

Related Questions