iOS--textview

来源:互联网 发布:淘宝松下军用笔记本 编辑:程序博客网 时间:2024/05/22 02:17

1.创建并初始化

创建UITextView的文件,并在.h文件中写入如下代码:

 


 
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface TextViewController : UIViewController <UITextViewDelegate>  
  4. {  
  5.             UITextView *textView;  
  1. }  
  2.   
  3. @property (nonatomic, strong) UITextView *textView;  
  4.   
  5. @end  




 

在.m文件中初始化这个textview,写入代码如下:

 


 
  1. 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.                
  12.   
  13. self.textView.text = @"Now is the time for all good developers tocome to serve their country.\n\nNow is the time for all good developers to cometo serve their country.";//设置它显示的内容  
  14.   
  15. self.textView.returnKeyType = UIReturnKeyDefault;//返回键的类型  
  16.   
  17. self.textView.keyboardType = UIKeyboardTypeDefault;//键盘类型  
  18.   
  19. self.textView.scrollEnabled = YES;//是否可以拖动  
  20.   
  21.                
  22.   
  23. self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度  
  24.   
  25.                
  26.   
  27. [self.view addSubview: self.textView];//加入到整个页面中  

  28.   
  1.                
  2.   
  3. [self.view addSubview: self.textView];//加入到整个页面中  


    textView.alpha = 1;
    textView.backgroundColor = [UIColor blackColor];
    textView.editable =NO;
    textView.textAlignment = UITextAlignmentCenter;
    textView.textColor = [UIColor whiteColor];
    textView.font = [UIFont fontWithName:@"Marker Felt" size:30];
    textView.text = @"从前sfsfdsfdsaaaaaaaaaaaaaaaaaaaaayufguighjgfuygggiugjkvgftvuytdcvtboybnbyubuvtyftyuruygyguyfytvtbiyiuuybtvc6r78vt7tb98yyfv67r6bt78v6r7cdeseerdftuyfgiyfyucghcchcghcghccgcghcghgyuuigyy89tr67r67xfcghhvjguugiuifuytftfyfuguiutfuftfyugiguiuifyufufyuyfgui";
    textView.contentOffset = CGPointMake(0, -100);
    textView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    textView.clipsToBounds = YES;
    textView.scrollEnabled = YES;
    [textView setCanCancelContentTouches:NO];
    textView.showsHorizontalScrollIndicator = NO;
    textView.showsVerticalScrollIndicator = NO;



http://blog.csdn.net/qq_31810357/article/details/49254969



0 0