[英]Change the font size of a UITextField in a UIAlertView
有誰知道如何在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];
}
在iOS 7.x之后,您無法自定義警報視圖的外觀,
在UIAlertView類參考中清楚地提到:
UIAlertView類旨在按原樣使用,不支持子類化。 此類的視圖層次結構是私有的, 不得修改 。
所以不幸的是,不可能改變textField字體,按鈕文本顏色等。
唯一的解決方案是使用自定義UIAlertView之一。
您可以使用以下方法之一創建自定義UIAlertView
:
並應用您的自定義textField
。
對於第二個選項,在CODialog.m ( addTextFieldWithPlaceholder
函數)中,您可以更改字體大小,或修改kCODialogTextFieldHeight
常量。
field.font = [UIFont systemFontOfSize:kCODialogTextFieldHeight - 8.0];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.