[英]UITextField not selectable
我正在嘗試為正在使用的應用創建登錄屏幕。 現在我有兩個UITextField,它們后面有一個圖像視圖。 當我嘗試單擊文本字段以輸入文本時,什么也沒有發生。 我花了很多時間試圖找出這個問題,但是找不到遇到類似問題的人。 在我的LoginViewController的viewDidLoad方法中,我有以下代碼:
`
[super viewDidLoad];
UIImageView *splashView = [[UIImageView alloc] initWithFrame:self.view.frame];
splashView.image = [UIImage imageNamed:@"Default-568h@2x.png"];
UITextField *username = [[UITextField alloc] initWithFrame:CGRectMake(90, 320, 140, 30)];
username.placeholder = @"username";
username.borderStyle = UITextBorderStyleRoundedRect;
username.returnKeyType = UIReturnKeyDone;
username.textAlignment = NSTextAlignmentLeft;
username.userInteractionEnabled = YES;
[splashView addSubview:username];
UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(90, 365, 140, 30)];
password.placeholder = @"password";
password.borderStyle = UITextBorderStyleRoundedRect;
password.textAlignment = NSTextAlignmentLeft;
[splashView addSubview:password];
[self.view addSubview:splashView];
`
任何幫助或建議,將不勝感激,謝謝。
更改添加圖像的位置:
[super viewDidLoad];
UIImageView *splashView = [[UIImageView alloc] initWithFrame:self.view.frame];
splashView.image = [UIImage imageNamed:@"Default-568h@2x.png"];
// The image behind
[self.view addSubview:splashView];
UITextField *username = [[UITextField alloc] initWithFrame:CGRectMake(90, 320, 140, 30)];
username.placeholder = @"username";
username.borderStyle = UITextBorderStyleRoundedRect;
username.returnKeyType = UIReturnKeyDone;
username.textAlignment = NSTextAlignmentLeft;
username.userInteractionEnabled = YES;
// Change this
[self.view addSubview:username];
UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(90, 365, 140, 30)];
password.placeholder = @"password";
password.borderStyle = UITextBorderStyleRoundedRect;
password.textAlignment = NSTextAlignmentLeft;
//And change this
[self.view addSubview:password];
如果您是另一個textField的另一個圖像,則首先添加視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.