iOS textView的使用总结

来源:互联网 发布:软件可靠性设计方案 编辑:程序博客网 时间:2024/05/18 02:18

在.h文件中声明:

@interface ProtocolViewController :UIViewController<UITextViewDelegate>

{

    UITextView *textView;

}


@property (nonatomic,retain)UITextView *textView;


@end


在.m中初始化:

self.textView=[[[UITextView alloc] initWithFrame:self.view.frame] autorelease]; //初始化大小并自动释放 
self.textView.textColor = [UIColor blackColor];//设置textview里面的字体颜色 
self.textView.font = [UIFont fontWithName:@"Arial"size:18.0];//设置字体名字和字体大小
self.textView.delegate = self;//设置它的委托方法 
self.textView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色               
self.textView.text = @"abcdefghi\nkjhk\nhkjhkjhksaejodslkae\nnfdkshekhfkdsae\nfdhskejhkfhskejh\ngfdhsgaejhgfjhdsgaejhgfjhdsgaejhgfdjsagejhgfhjsagejhgfdsjahgejhfgdsjha";//设置它显示的内容
self.textView.returnKeyType = UIReturnKeyDefault;//返回键的类型
self.textView.keyboardType = UIKeyboardTypeDefault;//键盘类型
self.textView.scrollEnabled = YES;//是否可以拖动           
self.textView.editable =NO;//禁止编辑
self.textView.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度           
[self.view addSubview: self.textView];//加入到整个页面中

原创粉丝点击