gpt4 book ai didi

ios - iOS NSTextAttachment无法将基线偏移量设置为零

转载 作者:行者123 更新时间:2023-12-01 22:11:32 24 4
gpt4 key购买 nike

NSMutableAttributedString * attrString =({

//单词
NSAttributedString * leftString = [[NSAttributedString alloc] initWithString:@“好”属性:@ {NSFontAttributeName:[UIFont systemFontOfSize:10]}]];

// 图片
NSAttributedString * attachString =({
UIImage * image = [UIImage imageNamed:@“项目标签”];
NSTextAttachment *附加= [NSTextAttachment新];
attach.image =图片;

[NSAttributedString attributedStringWithAttachment:attach];
});

NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithAttributedString:leftString];
[attrString appendAttributedString:attachString];

//设置行高
NSMutableParagraphStyle * style = [NSMutableParagraphStyle new];
style.maximumLineHeight = 22.5;
style.minimumLineHeight = 22.5;

[attrString addAttribute:NSParagraphStyleAttributeName值:样式范围:NSMakeRange(0,attrString.length)];

//设置baselineOffset
[attrString addAttribute:NSBaselineOffsetAttributeName值:@ 0范围:NSMakeRange(0,attrString.length)];

attrString;
});

如果图像附件之前有一些单词,则图像的attributedString的基线偏移量不能设置为0。

here is the demo project

最佳答案

我自己解决了。

只需将NSTextAttachment的bound.origin.y设置为字体的后代即可。

关于ios - iOS NSTextAttachment无法将基线偏移量设置为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53165149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com