【问题标题】:Set Image inline with text to UITextView in Objective C在Objective C中将带有文本的图像内联设置为UITextView
【发布时间】:2015-06-25 12:38:53
【问题描述】:

我想像下面的截图一样向 UITextView 添加内嵌文本的图像


我曾尝试使用NSTextAttachmentNSAttributedString,但它只在图像前后放置了一行。

请帮我解决这个问题。

【问题讨论】:

  • 我在发布这个问题之前已经尝试过这个,但它不符合我的要求。我也在我的问题中提到了这一点
  • 这张图不错。你也可以发布文本,以防图片链接失效吗?另外,您能否编辑您尝试过的各种方法以及为什么它们不起作用?

标签: ios uiimage uitextview


【解决方案1】:

你只需要使用'UIBezierPath'

例如,

txtvHtmlString.text = @“your long text…….”;

imgView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 100, 152, 128)];

imgView.image = [UIImage imageNamed:@"smily.png"];     
imgView.layer.cornerRadius = 10;
[txtvHtmlString addSubview:imgView];

如果你的文本更新了,别忘了更新 viewDidLayoutSubviews 中的 bezierpath。

- (void)viewDidLayoutSubviews {
    UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:imgView.frame];
    txtvHtmlString.textContainer.exclusionPaths  = @[exclusionPath];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-04
    相关资源
    最近更新 更多