我在Interface Builder中创建了这个约束。如果没有它,下面的文本视图会随着内容的增长而向上扩展,有了它,文本视图就会随着内容的增长而向下扩展。

如何在中以编程方式创建约束?
这是我尝试过的:
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_textView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:_internalScrollView //this is the parent view
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:0.0]];但它对任何事情都没有实质性的影响。
我使用的UITextView对象来自这个库https://github.com/MatejBalantic/MBAutoGrowingTextView,但这是对这个问题的一个转移注意力的问题。
发布于 2015-11-18 13:58:00
这是你需要做的。
[_internalScrollView addConstraint:[NSLayoutConstraint
constraintWithItem:_textView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:_internalScrollView //this is the parent view
attribute:NSLayoutAttributeTop
multiplier:1.0f
constant:300.0]]; // constant should be 300 as shown by you in screen shot顺便说一句,上面的屏幕截图显示您正在使用顶级布局向导而不是textView的父视图进行约束。如果是这种情况,则应根据您的需要在上面的代码中更改布局属性
https://stackoverflow.com/questions/33768713
复制相似问题