![](/img/trans.png)
[英]iOS - position view set distance from bottom of screen or keyboard (if it is showing) without subscribing to keyboard notifications
[英]Set keyboard on screen
有沒有辦法在加載視圖時將鍵盤設置在屏幕上,而不是使用
[textView becomeFirstResponder];
我需要這個,因為即使鍵盤已經固定在屏幕上,我希望用戶看到占位符文本。
使用以下代碼
- (void)viewDidLoad
{
[Super viewDidLoad];
textView = [ [UITextview alloc]initwithFrame:frame];// Customise TextView
textview.text = @"Enter your text here";
[textview becomeFirstResponder];
[self.view addSubview:textview];
}
這可能對你有所幫助
根據您的評論,當textView剛剛開始編輯時,不要隱藏占位符文本。 相反,您應該使用UITextView
的委托方法shouldChangeTextInRange:replacementText:
來計算shouldChangeTextInRange:replacementText:
文本的長度,如果它為零,則顯示占位符字符串,否則不顯示。
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSString* txt = [textView.text stringByReplacingCharactersInRange:range withString:text];
if([txt length] == 0)
// Show your place holder text
else
// Hide your place holder text
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.