1. 程式人生 > >給UITextView 頭部插入檢視(同理 給YYTextView加上頭部,解決scrollview和textview衝突的問題)

給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屬性