Change the font size of UITextField in UIAlertView

Does anyone know how to change the font size of a UITextField in a UIAlertView? The following is my code ...

- (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 font textField.font = [UIFont systemFontOfSize:16.0]; NSDictionary *attributes = @{ NSFontAttributeName: [UIFont systemFontOfSize:16.0]}; textField.typingAttributes = attributes; [alert show]; } 
+5
ios iphone uitextfield uialertview
source share
3 answers

After iOS 7.x, you cannot customize the appearance of alerts,

Why?

Because its hierarchy of representations is private.

This is clearly indicated in the UIAlertView Class Link :

The UIAlertView class is intended to be used as is, not subclass support. The presentation hierarchy for this class is private and should not be changed .

So, unfortunately, it is impossible to change the font textField, the color of the text of the buttons, etc.

The only solution is to use one of the custom UIAlertView.

+7
source share

You must use a custom alertview. Just check the link below.

DTAlertView

It has good animation, and a text box can also be added.

Once you use this, you do not need to write such large code.

Hope this helps.

+2
source share

You can create a custom UIAlertView using one of the following:

and apply your own textField .

For the second option in CODialog.m ( addTextFieldWithPlaceholder function) you can change the font size or change the constant kCODialogTextFieldHeight .

 field.font = [UIFont systemFontOfSize:kCODialogTextFieldHeight - 8.0]; 
0
source share

All Articles