首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITextView :使用UITextView text iOS内联UIButton

UITextView :使用UITextView text iOS内联UIButton
EN

Stack Overflow用户
提问于 2016-04-30 15:31:58
回答 3查看 949关注 0票数 1

我有一个在右下角有UIButtonUITextView。我的UITextView允许多行文本,即textView高度在键入enter键时动态增加(类似于短信应用程序)。但我的问题是,在输入文本时,文本会被放在UIButton后面。我希望文本在到达图像时停止,并在下一行继续,文本中没有任何中断。这个是可能的吗?

EN

回答 3

Stack Overflow用户

发布于 2016-04-30 17:54:38

这个解决方案对我很有效。我有UItextview的子类,我把这段代码放在那里。

代码语言:javascript
复制
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:_buttonClear.frame];
        self.textContainer.exclusionPaths  = @[exclusionPath];
票数 1
EN

Stack Overflow用户

发布于 2016-04-30 15:37:12

使用苹果公司提供的Text Kit Framework。你可以做到这一点

这是ray wenderlich tut https://www.raywenderlich.com/50151/text-kit-tutorial

具体地说,您必须为UITextView设置exclusionPaths

代码语言:javascript
复制
UIBezierPath* exclusionPath = [_timeView curvePathWithOrigin:myButton.center];
_textView.textContainer.exclusionPaths  = @[exclusionPath];
票数 0
EN

Stack Overflow用户

发布于 2016-04-30 19:31:41

试试下面的代码:

代码语言:javascript
复制
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithRect:Button.frame];
        self.textContainer.exclusionPaths  = @[exclusionPath];

使用UITextView委托并执行以下操作:

代码语言:javascript
复制
- (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;
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36952127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档