-(NSAttributedString *)imagesWithimgName:(NSString* )imgName offsetY:(CGFloat)offsetY
{
NSTextAttachment * textAttachment = [[NSTextAttachment alloc]init];
UIImage * smileImage = [ UIImage imageNamed:imgName];
textAttachment.image = smileImage ;
textAttachment.bounds = CGRectMake(0, offsetY, smileImage.size.width, smileImage.size.height);
return [NSAttributedString attributedStringWithAttachment:textAttachment];
}
-(void)appendImgStr:(NSString* )imgName offsetY:(CGFloat)offsetY
{
[self appendAttributedString:[self imagesWithimgName:imgName offsetY:offsetY]];
}图文混排之NSAttributedString
最新推荐文章于 2021-03-19 15:30:37 发布
本文介绍了一个Objective-C方法,用于将指定名称的图片插入到NSAttributedString中,并允许调整图片的垂直偏移量。通过创建并配置NSTextAttachment对象,该方法能够灵活地控制图片的位置和大小。
906

被折叠的 条评论
为什么被折叠?



