Reputation: 12753
Does anyone know how to change the font size of a UITextField within 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's font
textField.font = [UIFont systemFontOfSize:16.0];
NSDictionary *attributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:16.0]};
textField.typingAttributes = attributes;
[alert show];
}
Upvotes: 5
Views: 5990
Reputation: 31637
You have to use custom alertview. Just check below link.
It has good animation and textfield can be added too.
Once you use this, you don't have to write such big code.
Hope it helps.
Upvotes: 2
Reputation: 18470
After iOS 7.x you cannot customize the appearance of alert views,
It is mentioned clearly in UIAlertView Class Reference:
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
So unfortunately it is impossible to change the textField font, buttons text color .. etc.
The only solution is using one of the custom UIAlertView's.
Upvotes: 8
Reputation: 4530
You can create a custom UIAlertView
using one of this:
and apply your custom textField
.
For the second option, in CODialog.m (addTextFieldWithPlaceholder
function) you can change the font size, or modify kCODialogTextFieldHeight
constant.
field.font = [UIFont systemFontOfSize:kCODialogTextFieldHeight - 8.0];
Upvotes: 0