UIAlertController或UITextField UILabel UILabel
我需要添加一些标签UIAlertController
和研究后证明,没有正常的方法来做到这一点。但由于可以添加UITextField
,我决定将UITextField
的外观更改为UILabel
(没有边框和背景颜色)。但改变其背景颜色清晰和边框样式没有帮助。我怎样才能做到这一点?
下面是代码:UIAlertController或UITextField UILabel UILabel
- (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添加自定义标签良好的UI外观。
要做到这一点的最好方法是编写自定义UIView,使其感觉和行为像UIAlertView或使用github中的以下库之一。
到目前为止,SDCAlertView对我来说运行良好。 –
使用本
textField.placeholder = @"Text: ";
代替
textField.text = @"Text: ";
感谢您的回答,但这并没有帮助 –
为什么您要添加标签? –
不中UIAlert消息像一个标签。你基本上想在UIAlert中使用一个自定义标签,以便你可以自定义它的属性(改变字体,颜色等)?请让我知道 – KrishnaCA
@Chaitanya我已更新我的问题。在那里你可以看到我想要做的事情。 –