给UITextView 头部插入视图(同理 给YYTextView加上头部,解决scrollview和textview冲突的问题)

PS: _headView要成为textview的子view

     [textview addsubview:_headview];

有时候我们需要在UITextView的上面插入视图的样式,并且要求其随着输入一起滑动,这时候没有必要再加一个UIScrollView了,可以直接设置UITextView的一个属性,设置如下:

_headerView = [[UIView alloc] initWithFrame:CGRectMake(0,-88,self.view.frame.size.width,88)];
  • 1
  • 1
_textView.textContainerInset = UIEdgeInsetsMake(CGRectGetHeight(_headerView.frame), 0, 0, 0);
  • 1
  • 2
  • 1
  • 2

如果是UIScrollView、UITableView,可以使用contentInset属性

你可能感兴趣的:(ios进阶)