zoukankan      html  css  js  c++  java
  • UITextView使用中的一点问题(无法从第一行开始显示)的解决办法

    这是UITextView的指定初始化方法.

    - (instancetype)initWithFrame:(CGRect)frame textContainer:(NSTextContainer *)textContainer

    但是在实际的使用过程中,我们一般只需要指定其Frame即可.

    初始化方法中第二个参数textContainer,这个是官方解释
    The text container to use for the receiver (can be nil).这个类未研究.但是看到可以设置为nil,也就是说在一定的条件下必须设置为非空.

    如下这种情况,在一个视图中创建一个UITextView的话,textView是可以正常使用的.

    UITextView *introduceGroupField = [[UITextView alloc] initWithFrame:CGRectMake(27.5, 180, 265, 100)];
        introduceGroupField.text = @"北京大学校社联电视剧的健康的几多的解决的可伶搜哦上拉上拉山口胜平是11111111";
        introduceGroupField.font = [UIFont fontWithName:@"Didot" size:15];
        introduceGroupField.userInteractionEnabled = NO;
        //自动换行.此处可以写成view;
        introduceGroupField.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
        [self.view addSubview:introduceGroupField];
    但是今天在使用的过程中,我需要读取到textview的内容,于是便将其声明成了属性,然后继续采用上述的方法进行初始化.便出现了问题.创建出得textView的上部总是有一段地方不能显示文字也不能点击.视图的contentOffset明显有问题,但是我试着调整了其contentOffset,但是没有作用.最后,我是这么解决的

        UITextView * v = [[UITextView alloc] init];
        [self.view addSubview:[v autorelease]];
    然后再上上述方法那样初始化TextView,添加到控制器的视图上,就发现,后加的TextView就可以正常使用了.

    想了一下,在声明为属性后,UITextView是必须有一个容器的.




  • 相关阅读:
    python函数定义,函数参数
    jmeter之实战总结
    Codeforces Round #384 (Div. 2) B. Chloe and the sequence
    Codeforces Round #384 (Div. 2) C. Vladik and fractions
    CodeForces
    Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
    Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift
    CodeForces
    CodeForces
    Codeforces Round #382 (Div. 2) B. Urbanization
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576208.html
Copyright © 2011-2022 走看看