小编Eri*_*hen的帖子

([NSAttributedString boundingRectWithSize:options:context:])方法无法在NSTextAttachment中获得正确的大小

在我的代码中:

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"12123"];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"002"];
attachment.bounds = CGRectMake(0, 0, 20, 20);

[str insertAttributedString:[NSAttributedString attributedStringWithAttachment:attachment] atIndex:2];
CGRect rect = [str boundingRectWithSize:CGSizeMake(200, CGFLOAT_MAX)
                                options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                context:nil];
Run Code Online (Sandbox Code Playgroud)

结构'rect'不正确,为什么?

image ios textkit

6
推荐指数
1
解决办法
516
查看次数

标签 统计

image ×1

ios ×1

textkit ×1