0

如何UITextView将字符串附加到新行,如下图所示?谢谢你帮助我。

这是我的代码。

主要代码:

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

}

在此处输入图像描述

4

0 回答 0