在UIAlertView中更改UITextField的字体大小

0x1*_*41E 5 iphone uitextfield uialertview ios

有谁知道如何在UIAlertView中更改UITextField的字体大小?以下是我的代码......

- (void) editTitle
{
    NSString *string = kLocalizedString(@"Edit Title");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                message:string
                                               delegate:self
                                      cancelButtonTitle:@"Cancel"
                                      otherButtonTitles:@"OK", nil];

    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *textField = [alert textFieldAtIndex:0];
    if (!self.title) {
        textField.text = nil;
    }
    else {
        textField.text = self.title;
    }

    textField.clearsOnBeginEditing = NO;
    textField.clearButtonMode = UITextFieldViewModeAlways;
    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    textField.clearsContextBeforeDrawing = NO;

    // These statements have no effect on the size of the text field's font
    textField.font = [UIFont systemFontOfSize:16.0];
    NSDictionary *attributes = @{
                NSFontAttributeName: [UIFont systemFontOfSize:16.0]}; 
    textField.typingAttributes = attributes;

    [alert show];
}
Run Code Online (Sandbox Code Playgroud)

nul*_*ull 8

在iOS 7.x之后,您无法自定义警报视图的外观,

为什么?

因为它的视图层次结构是私有的

UIAlertView类参考中清楚地提到:

UIAlertView类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的, 不得修改.

所以不幸的是,不可能改变textField字体,按钮文本颜色等.

唯一的解决方案是使用自定义UIAlertView之一.