A UiTextView with an edge-to-edge exception loop makes all text fade

I have one UITextView, and I want to add a custom one to it UIViewand make the text flow higher and lower as follows:

+----------------+
|------txt-------|
|                |
|     UIView     |   
|                |
|------txt-------|
|----------------|
|----------------|
+----------------+

I tried to achieve this by adding an exception path that has width UITextViewand height UIView, for example:

CGRect exclusionFrame=CGRectMake(0, 
                                CGRectGetMinY(element.frame),
                                self.textView.textContainer.size.width,
                                CGRectGetHeight(element.frame)); 
self.textView.textContainer.exclusionPaths=@[[UIBezierPath bezierPathWithRect:exclusionFrame]];

But for some reason, if the width of the exception path is equal to the width of the textView, the text below UIView(aka element) will disappear. When I reduce the width of the exception path by one, the text appears with a column with one letter next to the UIViewfollowing:

+----------------+
|------txt-------|
|a               |
|d     UIView    |   
|e               |
|------txt-------|
|----------------|
|----------------|
+----------------+

Why can't I create an exclusion path from edge to edge and is there a way to overcome this predicament?

+4
4

. UiTextView , , , :

-(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];

} 
0

, , \n\r\n\r . , , .

+2

textView.textContainer.lineFragmentPadding = 0 textView.textContainerInset = UIEdgeInsetsZero textView.contentInset = UIEdgeInsetsZero
.

0

swift, switch objective-c.

UITextView Scrolling Enabled = true. , .

  1. , enable = true
let path = UIBezierPath(rect: myview.frame)
textView.textContainer.exclusionPaths = [path]
self.textView.addSubview(myview)
  1. And I turn off scrolling when I change the text of a UITextView
func setText( message: String ) {
    textView.isScrollEnabled = false
    textView.text = message
    textView.isScrollEnabled = true
}

This solves my problem. I hope this helps.

0
source

All Articles