自從 iOS 7 開始,很多人說無法加入 custom view。
若要帶輸入框(UITextField)的話,雖然本身有提供好幾種模式,如:UIAlertViewStyleLoginAndPasswordInput (帳號&密碼)、UIAlertViewStylePlainTextInput (文字)等。
結果發現要做個重設密碼,需要2個 UITextField 且為 Secure 模式就無法度了,因為 UIAlertViewStyleLoginAndPasswordInput 其中有1個不是 Secure 模式。
拜讀 google 大神後找到好心人提供方法,去設定 UIAlertView 裡的 accessoryView 參數即可。
[alertView setValue:customContentView forKey:@"accessoryView"];
參考來源:http://stackoverflow.com/questions/18886048/ios-multiple-text-fields-on-a-uialertview-in-ios-7
2014年7月19日 星期六
2012年8月30日 星期四
[iOS] 將輸入框 (UITextField) 收起的方法
每次使用 UITextField 來讓使用者輸入文字,但在收起來這件事總是不少麻煩。
記錄一下幾個收起的方法:
1.實作 UITextFieldDelegate 的函式在按下確定 (Return、Done) 後收起
2.手指點擊畫面後收起
記錄一下幾個收起的方法:
1.實作 UITextFieldDelegate 的函式在按下確定 (Return、Done) 後收起
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
2.手指點擊畫面後收起
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)];
tapRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapRecognizer];
- (void)handleBackgroundTap:(UITapGestureRecognizer *)sender
{
[textField resignFirstResponder];
}
訂閱:
文章 (Atom)