将字体大小设置为 UIActionSheet 标题

set font size to UIActionSheet title

我需要设置尺寸 UIActionSheet 标题 "Select option to Copy"

使用此代码:

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

您可以使用此 delgate

更改 uiactionsheet 的标题字体
  -(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;
            }
        }
    }

您可以利用运行时属性来设置字体。通过使用 NSAttributedString 你可以做到这一点。

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