码迷,mamicode.com
首页 > 其他好文 > 详细

UITextView

时间:2015-09-30 16:16:36      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

//初始化
    self.textView=[[UITextView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    //设置内容
    self.textView.text=@"显示内容";
    //设置字体
    self.textView.font=[UIFont systemFontOfSize:20];
    //设置字体颜色
    self.textView.textColor=[UIColor whiteColor];
    //设置背景色
    self.textView.backgroundColor=[UIColor whiteColor];
    //设置返回键样式
    self.textView.returnKeyType=UIReturnKeyDefault;
    //设置键盘样式
    self.textView.keyboardType=UIKeyboardTypeDefault;
    //是否允许拖动
    self.textView.scrollEnabled=NO;
    //自适应
    self.textView.autoresizingMask=UIViewAutoresizingFlexibleHeight;
    //是否允许编辑
    self.textView.editable=NO;
    //添加到视图
    [self.view addSubview:self.textView];

//TextView继承自ScrollView,所以也具有偏移量属性,只是在ios7环境中,textView并不能立即更新contentSize,采用以下方法可以解决这个问题
    float height;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        
        CGRect textFrame=[[self.textView layoutManager]usedRectForTextContainer:[self.textView textContainer]];
        height = textFrame.size.height;
        
    }else {
        
        height = self.textView.contentSize.height;
    }

 

UITextView

标签:

原文地址:http://www.cnblogs.com/kyuubee/p/4849382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!