你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> UITextView控件詳解

UITextView控件詳解

編輯:IOS開發綜合

self.textView = [[[UITextView  alloc] initWithFrame:self.view.frame] autorelease]; //初始化大小並自動釋放
 2
 3 self.textView.textColor = [UIColor blackColor];//設置textview裡面的字體顏色 
 4
 5 self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];//設置字體名字和字體大小 
 6
 7 self.textView.delegate = self;//設置它的委托方法 
 8
 9 self.textView.backgroundColor = [UIColor whiteColor];//設置它的背景顏色
10
11 self.textView.text = @"Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country.";//設置它顯示的內容 
12
13 self.textView.returnKeyType = UIReturnKeyDefault;//返回鍵的類型 
14
15 self.textView.keyboardType = UIKeyboardTypeDefault;//鍵盤類型 
16
17 self.textView.scrollEnabled = YES;//是否可以拖動 
18
19 self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自適應高度
20
把鍵盤的回車鍵當初鍵盤彈回按鈕
pragma mark - UITextView Delegate Methods    

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{   

    if ([text isEqualToString:@"\n"]) {   

        [textView resignFirstResponder];   

        return NO;   

    }

    return YES;   

}
對textView字數限制
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text   
{   
    if (range.location>=100)    
    {   
        return  NO;   
    }   
    else    
    {   
        return YES;   
    }   
}   
作者:lmmilove

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved