Ios UIAlertView UITextField显示黑色边框
我正在使用textinput创建UIAlertView,但尽管我清除了背景并为边框添加了颜色,但它显示的是黑色边框Ios UIAlertView UITextField显示黑色边框,ios,objective-c,uialertview,Ios,Objective C,Uialertview,我正在使用textinput创建UIAlertView,但尽管我清除了背景并为边框添加了颜色,但它显示的是黑色边框 UIAlertView *alerttorename=[[UIAlertView alloc]initWithTitle:@"Dropbox Export" message:@"Export As:" delegate:projectDetailsReference cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
UIAlertView *alerttorename=[[UIAlertView alloc]initWithTitle:@"Dropbox Export" message:@"Export As:" delegate:projectDetailsReference cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
alerttorename.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alerttorename textFieldAtIndex:0] setText:[appDelegate.projectName stringByDeletingPathExtension]];
UITextField *textField = [alerttorename textFieldAtIndex:0];
[textField setBackgroundColor:[UIColor clearColor]];
textField.borderStyle=UITextBorderStyleRoundedRect ;
textField.layer.borderColor=[[UIColor lightGrayColor]CGColor];
textField.layer.borderWidth = 0.1f;
textField.layer.cornerRadius = 5;
textField.clipsToBounds = YES;
alerttorename.tag=233;
[alerttorename show];
请参阅此示例,UIAlertController:
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:alertTitle
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder = NSLocalizedString(@"LoginPlaceholder", @"Login");
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder = NSLocalizedString(@"PasswordPlaceholder", @"Password");
textField.secureTextEntry = YES;
}];
文本字段的值可以在OK操作处理程序中检索:
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
UITextField *login = alertController.textFields.firstObject;
UITextField *password = alertController.textFields.lastObject;
}];
有关UIAlertController的更多信息,请参阅此。将此类别用于
UIView
以在iOS>7.0
中显示alertView
。在这里,您不需要担心UIAlertView
或UIAlertViewController
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
@interface UIView (AlertView)
+( void )showSimpleAlertWithTitle:( NSString * )title
message:( NSString * )message
cancelButtonTitle:( NSString * )cancelButtonTitle;
@end
此类别的用法如下:
[UIView showSimpleAlertWithTitle:@"Title here" message:@"Message here" cancelButtonTitle:@"Ok"];
iOS8中不推荐使用“UIAlertView”,更好的用户是“UIAlertController”。。请参考我的答案。。!!尽管你的答案与现代API相当,但有些时候它是没有用的。如果要为iOS<8.x提供向后兼容性,则不能使用
UIAlertController
。所以在某种程度上,你没有回答最初的问题。如果有人向你要苹果,你不能只给他们橘子,然后说,这更好。
[UIView showSimpleAlertWithTitle:@"Title here" message:@"Message here" cancelButtonTitle:@"Ok"];