UIAlertController custom font, size, color

后端 未结 25 2087
遥遥无期
遥遥无期 2020-11-22 09:06

I am using new UIAlertController for showing alerts. I have this code:

// nil titles break alert interface on iOS 8.0, so we\'ll be using empty strings
UIAle         


        
25条回答
  •  暖寄归人
    2020-11-22 09:47

    I work for Urban Outfitters. We have an open source pod, URBNAlert, that we used in all of our apps. It's based off of UIAlertController, but is highly customizable.

    Source is here: https://github.com/urbn/URBNAlert

    Or simply install by the pod by placing URBNAlert in your Podfile

    Heres some sample code:

    URBNAlertViewController *uac = [[URBNAlertViewController alloc] initWithTitle:@"The Title of my message can be up to 2 lines long. It wraps and centers." message:@"And the message that is a bunch of text. And the message that is a bunch of text. And the message that is a bunch of text."];
    
    // You can customize style elements per alert as well. These will override the global style just for this alert.
    uac.alertStyler.blurTintColor = [[UIColor orangeColor] colorWithAlphaComponent:0.4];
    uac.alertStyler.backgroundColor = [UIColor orangeColor];
    uac.alertStyler.textFieldEdgeInsets = UIEdgeInsetsMake(0.0, 15.0, 0.0, 15.0);
    uac.alertStyler.titleColor = [UIColor purpleColor];
    uac.alertStyler.titleFont = [UIFont fontWithName:@"Chalkduster" size:30];
    uac.alertStyler.messageColor = [UIColor blackColor];
    uac.alertStyler.alertMinWidth = @150;
    uac.alertStyler.alertMaxWidth = @200;
    // many more styling options available 
    
    [uac addAction:[URBNAlertAction actionWithTitle:@"Ok" actionType:URBNAlertActionTypeNormal actionCompleted:^(URBNAlertAction *action) {
          // Do something
    }]];
    
    [uac addAction:[URBNAlertAction actionWithTitle:@"Cancel" actionType:URBNAlertActionTypeCancel actionCompleted:^(URBNAlertAction *action) {
          // Do something
    }]];
    
    [uac show];
    

提交回复
热议问题