第一个UITextview文本不显示
我在viewController中插入了多个UITextviews,直到双击它才显示出第一个textViews文本。 然后它会滚动,如果再次双击它,它会向下滚动,我再也看不到它了。
然后,我尝试添加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文本 – “名称”,比其他所有的都低。
UIViewController有一个自动调整的ScrollViewInsets属性,默认是YES。 由于UITextView是一个ScrollView,你添加的第一个UITextView会自动添加一个顶部插入。
解决方法:在您的视图控制器的viewDidLoad或init中,将self.automaticallyAdjustsScrollViewInsets设置为NO。