如何在设置exclusionPaths后将字符串附加到新行而不是使用NSTextAttachment?

时间:2015-07-23 10:54:25

标签: ios uibezierpath textkit nstextcontainer

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

}

enter image description here

0 个答案:

没有答案