我有一個UITextView
,其中UIButton
位於右下角。我的UITextView
允許使用多行文本,即在輸入Enter鍵時textView高度會動態增加(類似於SMS應用程序)。但我的問題是,在輸入文字時,文字落後於UIButton
。我希望文字在到達圖像時停止,並在下一行繼續而不會有任何文字中斷。這可能嗎? UITextView:使用UITextView文本內聯UIButton iOS
1
A
回答
0
使用由蘋果提供的Text Kit Framework。你可以做到這一點
這裏是射線wenderlich嘖嘖 https://www.raywenderlich.com/50151/text-kit-tutorial
具體來說,你所要做的部分設置exclusionPaths
爲您的UITextView
UIBezierPath* exclusionPath = [_timeView curvePathWithOrigin:myButton.center];
_textView.textContainer.exclusionPaths = @[exclusionPath];
+0
謝謝。我會嘗試一下。 – JMS
1
對於我這種解決方案的工作。我有我把這個代碼的UItextview的子類。
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:_buttonClear.frame];
self.textContainer.exclusionPaths = @[exclusionPath];
+0
是的,我嘗試了上面的一樣。但問題是,我的'UITextView'高度不斷增加,這導致y值發生變化。在這種情況下我該怎麼辦? – JMS
0
試試下面的代碼:
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:Button.frame];
self.textContainer.exclusionPaths = @[exclusionPath];
使用UITextView的代表和這樣做,
- (void)textViewDidChange:(UITextView *)textView
{
//Get Buttons Y position and Allow TextView Frame changes until it is less than or equal buttons Y position
if (textView.frame.origin.y+textView.frame.size.height < Button.frame.origin.y) {
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
}
}
相關問題
- 1. 從UIButton編輯UItextview
- 2. uitextview內下劃線文本
- 3. UITextView富文本?
- 4. UITextView內的界面生成器UIButton
- 5. 使用CoreText模擬UITextView文本渲染?
- 6. UITextView Clickable,與UIButton差不多
- 7. 混淆UITextView,UIButton和BOOL
- 8. 在Swift中使用UITextView包裝文本
- 9. iOS 7 UITextView Bug
- 10. UITextView文本被截斷 - iOS 10
- 11. 的iOS 7 - UITextView的剪裁文本
- 12. UITextView動態寬度與文本iOS
- 13. 定製的iOS UITextView的文本
- 14. UITextView中的iOS可點擊文本
- 15. iOS中的UITextView文本對齊
- 16. UITextView大綱文本
- 17. UITextView文本消失
- 18. 刪除UITextView文本
- 19. UITextView隱藏文本
- 20. 用UITextView替換UITableViewCell文本
- 21. 禁用文本選擇UITextView
- 22. 使用UITextView的文本格式化
- 23. 如何在UITextView UITextView中的任何光標位置插入UIButton
- 24. 使用PageControl的長文本的UITextView
- 25. UITextView,全屏模式和用UIButton退出
- 26. UItextView iOS 7問題
- 27. 的iOS 5:UITextView的
- 28. 使用UITextVIew
- 29. iOS - 如何使用佔位符文本創建UITextView?
- 30. 本地化UITextView
嗨@JMS,你找到了一個合適的解決方案? – adnako
我使用排除路徑來實現它。但是每當'UITextView'中的文本發生變化時,我們需要重置排除路徑(嘗試在'scrollViewDidScroll'方法中) – JMS
謝謝,我將繼承UITextView的子類以便就地修改排除路徑。 – adnako