UITextView contentInset is not working

…衆ロ難τιáo~ 提交于 2019-12-05 20:53:11

For iOS7 use textContainerInset

@property(nonatomic, assign) UIEdgeInsets textContainerInset NS_AVAILABLE_IOS(7_0);

For Bellow iOS7 use contentInset and setting UIEdgeInsetsMake as bellow syntax.

UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
    UIEdgeInsets insets = {top, left, bottom, right};
    return insets;
}

According to your code you are setting only top side inset But if you wish to set all side you have to set content inset like bellow :-

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
       _TxtViewSummary.contentInset = UIEdgeInsetsMake(10, 0, 10, 0);
    } else {
       _TxtViewSummary.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
    }

That look like this:-

Use this:

[txtt  setTextContainerInset:UIEdgeInsetsMake(7, 7, 0, 0)];

Also, the right way to position element is in layoutSubviews method.

Another possible solution is the following:

self.textView.contentInset = UIEdgeInsets(top: 740.0, left: 0, bottom: 20.0, right: 0)
self.textView.contentOffset = CGPoint(x: 0, y: -740)

I was getting an unwanted behaviour where textContentInset was placing the text properly to begin with, but then the content would scroll off screen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!