第一个UITextview文本未显示

时间:2014-12-22 08:40:29

标签: ios objective-c uiscrollview uitextview

我在viewController上插入了多个UITextviews,直到我双击它才会显示第一个textViews文本。它然后向上滚动,如果我再次双击它,它会向下滚动,我再也看不到它了。

enter image description here enter image description here

然后我尝试手动添加UITextViews(不是以编程方式),它做了同样的事情。奇怪的是,这只发生在页面上的一个uitextview上。

更新

我会发布代码,但我不认为它是相关的,因为我说我手动将UITextViews放在另一个vieController上,它做了同样的事情,但我会发布它以防万一:

int heightBetweenLabels = 10;
int labelWidth = 200;
int labelHeight = 1;
int height = 0;
int position = 0;

for (int i = 0; i < [currentListInfo count]; i++) {
    if (height == 0 && position == 0)
    {
        height = 70;
        labelHeight = 50;
    }
    label = [[UITextView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - labelWidth) / 2, height + position + heightBetweenLabels, labelWidth, labelHeight)];

    [label setBackgroundColor:[UIColor lightGrayColor]];
    [label setTextColor:[UIColor blackColor]];
    label.scrollEnabled = NO;
    [label setEditable:NO];


    self.label.text = nil;

    label.dataDetectorTypes = UIDataDetectorTypeAll;
    [self textViewFitToContent:label];
    [self.view addSubview:label];
    [label setText:[currentListInfo objectAtIndex:i]];

    label.contentInset = UIEdgeInsetsZero;
    height = label.frame.size.height;
    position = label.frame.origin.y;
}

更新 - 2

这基本上就是发生了什么。我不知道为什么,但是textView文本 - “name”比其他所有文本都要低。

enter image description here

3 个答案:

答案 0 :(得分:7)

UIViewController有一个automaticAdjustsScrollViewInsets属性,默认为YES。由于UITextView是ScrollView,您添加的第一个UITextView将自动添加一个顶部插入。

解决方案:在视图控制器的viewDidLoad或init中,将self.automaticallyAdjustsScrollViewInsets设置为NO。

答案 1 :(得分:2)

迅速5
这对我有用:

textView.isScrollEnabled = false

答案 2 :(得分:0)

可能是因为您的UITextView嵌入UIStackViewAlignment属性设置不正确的Distribution中。

如果UIStackView Alignment Distribution 属性是..

enter image description here

将其更改为下方可能会修复此问题。

enter image description here

相关问题