具有边到边排除路径的UiTextView会导致所有文本消失 [英] UiTextView with edge to edge exclusion path cause all the text to disappear
问题描述
我有一个 UITextView
,我想为它添加一个自定义的 UIView
,并使文本在上面流动,如下所示:
I have a UITextView
and i want to add a custom UIView
to it and make the text flow above and below like so:
+----------------+
|------txt-------|
| |
| UIView |
| |
|------txt-------|
|----------------|
|----------------|
+----------------+
我试图通过添加一个具有 UITextView
宽度的排除路径以及 UIView
的高度来实现这一点:
I tried to achieve this by adding an exclusion path that has the UITextView
width and the UIView
's height like so:
CGRect exclusionFrame=CGRectMake(0,
CGRectGetMinY(element.frame),
self.textView.textContainer.size.width,
CGRectGetHeight(element.frame));
self.textView.textContainer.exclusionPaths=@[[UIBezierPath bezierPathWithRect:exclusionFrame]];
但由于某种原因,如果排除路径的宽度等于textView的宽度,则<$ c下面的所有文本$ c> UIView (又名元素
)消失。当我将排除路径的宽度减少一个时,文本显示为 UiView
旁边的一个字母列,如下所示:
But for some reason if the exclusion path's width equal the textView's width all the text below the UIView
(aka element
) disappear. When i reduce the exclusion path's width by one the text appear with a one letter column next to the UiView
like this:
+----------------+
|------txt-------|
|a |
|d UIView |
|e |
|------txt-------|
|----------------|
|----------------|
+----------------+
为什么我不能创建边缘到边缘的排除路径,是否有解决这种困境的方法?
Why can't i create a edge to edge exclusion path and is there a way around this predicament?
推荐答案
最终成为故事板。我只从视图中取出UiTextView并以编程方式初始化它似乎解决了问题:
It ended up being the storyboard. I took only the UiTextView out of the view and initialized it programmatically that seemed to solve the problem:
-(void) viewDidLoad{
self.textView=[[UITextView alloc] init];
self.textView.translatesAutoresizingMaskIntoConstraints=NO;
[self.view addSubview:self.textView];
NSDictionary* views = @{@"textView": self.textView};
NSArray* vContrains=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[textView]-50-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views];
NSArray* hContrains=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[textView]-50-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views];
[self.view addConstraints:vContrains];
[self.view addConstraints:hContrains];
}
这篇关于具有边到边排除路径的UiTextView会导致所有文本消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!