0

How UITextView can append string to a new line like below screenshot show? Thanks for helping me.

Here is my code.

main code:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSTextStorage *storage = [NSTextStorage new];
    NSLayoutManager *layoutManager = [NSLayoutManager new];
    [storage addLayoutManager:layoutManager];
    NSTextContainer *textContainer = [NSTextContainer new];
    [layoutManager addTextContainer:textContainer];

    //setting exclusionPaths
    UIImage *image = [UIImage imageNamed:@"sample"];
    CGRect areaRect = CGRectMake(10, 50, 355, 180);
    UIBezierPath *ovalPath = [UIBezierPath bezierPathWithRect:areaRect];
    textContainer.exclusionPaths = @[ovalPath];

    //append text below image ,how to do?
    NSAttributedString *text  = [[NSAttributedString alloc]initWithString:@"\ntest\ntet2\ntet2\ntet2\ntet2"];
    [storage appendAttributedString:text];

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 375, 600) textContainer:textContainer];

    [self.view addSubview:textView];
    // add a image to exclusionPaths area
    [textView addSubview:showImageView];

}

enter image description here

clemens
  • 16,716
  • 11
  • 50
  • 65
james
  • 643
  • 4
  • 24
  • possible duplicate of [How to add image and text in UITextView in IOS?](http://stackoverflow.com/questions/24010035/how-to-add-image-and-text-in-uitextview-in-ios) – Vizllx Jul 23 '15 at 11:03
  • not the same , I want to use exclusionPaths not NSTextAttachment :) – james Jul 23 '15 at 12:50

0 Answers0