How to change font size and color of UIAlertAction in UIAlertController

后端 未结 4 1465
孤独总比滥情好
孤独总比滥情好 2021-01-06 17:57

In the image above how to change the font size and color of \"Done\", \"Some Other action\"? and how to change the font size and color of \"title\", and \"message\"

4条回答
  •  清酒与你
    2021-01-06 18:03

    This is from another stack overflow post but seems to work fine. Post found here.

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Dont care what goes here, since we're about to change below" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting the great... Hulk Hogan!"];
    [hogan addAttribute:NSFontAttributeName
              value:[UIFont systemFontOfSize:50.0]
              range:NSMakeRange(24, 11)];
    [alertVC setValue:hogan forKey:@"attributedTitle"];
    
    
    
    UIAlertAction *button = [UIAlertAction actionWithTitle:@"Label text" 
                                        style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action){
                                                    //add code to make something happen once tapped
    }];
    UIImage *accessoryImage = [UIImage imageNamed:@"someImage"];
    [button setValue:accessoryImage forKey:@"image"];
    

    To change the color of the text with the following, adding it before the line setting [alertVC setValue:hogan forKey:@"attributedTitle"];

    [hogan addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,35)];
    

提交回复
热议问题