【发布时间】:2016-06-08 07:20:30
【问题描述】:
我需要给UIAlertController添加一些标签,经过研究发现没有正常的方法可以做到这一点。但是由于可以添加UITextField,所以我决定将UITextField 的外观更改为与UILabel 相似(没有边框和背景颜色)。但是将其背景颜色更改为 clear 并将边框样式更改为 none 并没有帮助。我怎样才能做到这一点?
这是代码:
- (void)test
{
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Test Title"
message:@"Test Message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do Some action here
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = @"Text: ";
textField.backgroundColor = [UIColor blueColor];
textField.borderStyle = UITextBorderStyleNone;
textField.backgroundColor = [UIColor clearColor];
[textField setUserInteractionEnabled:NO];
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
}];
[self presentViewController:alert animated:YES completion:nil];
}
【问题讨论】:
-
UIAlert 中的消息的行为不像标签。您是否基本上想要 UIAlert 中的自定义标签,以便您可以自定义它的属性(更改字体、颜色等)?请告诉我
-
@Chaitanya 我已经更新了我的问题。在那里你可以看到我尝试做的事情。
标签: ios objective-c uitextfield uilabel uialertcontroller