UITextField in UIAlertController (border, backgroundColor)

前端 未结 8 1844
陌清茗
陌清茗 2020-12-01 16:38

Here is a screenshot of a UIAlertController. I was just playing around custom fonts and textfield properties but I was unable to accomplish the fol

8条回答
  •  半阙折子戏
    2020-12-01 17:20

    This is very hacky, so examine it well before using (tested on iOS 8.3):

    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                                                                   message:@"This is an alert."
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    
        textField.placeholder = @"This is my placeholder";
        textField.backgroundColor = [UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1.0]; // You can change it to whatever color you want
        [textField superview].backgroundColor = textField.backgroundColor;
        [[textField superview] superview].backgroundColor = [UIColor whiteColor];
    
    }];
    

提交回复
热议问题