相关疑难解决方法(0)

在单行UILabel旁边显示NSTextAttachment图像

我想将NSTextAttachment图像附加到我的属性字符串并使其垂直居中.

我使用以下代码来创建我的字符串

        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:DDLocalizedString(@"title.upcomingHotspots") attributes:attrs];
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        attachment.image = [[UIImage imageNamed:@"help.png"] imageScaledToFitSize:CGSizeMake(14.f, 14.f)];
        cell.textLabel.attributedText = [str copy];
Run Code Online (Sandbox Code Playgroud)

但是,图像看起来与单元格textLabel的顶部对齐.

在此输入图像描述

如何更改绘制附件的矩形?

objective-c uilabel nstextattachment ios swift

106
推荐指数
8
解决办法
3万
查看次数

标签 统计

ios ×1

nstextattachment ×1

objective-c ×1

swift ×1

uilabel ×1