我有一个标签,我试图在标签的开头放置一个符号图像,然后在其后放置一些文本。这有效,但符号图像永远不会改变大小。我在 UIImageSymbolConfiguration 中提供的大小无关紧要,它保持很小。如果我使用此代码并将图像放入 UIImageView 中,则图像会按预期变大。我在这里所做的与符号图像配置相关的任何事情有问题吗?
UILabel *label = [[UILabel alloc] init];
NSString *title = @"Some Text";
label.adjustsFontForContentSizeCategory = YES;
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", title] attributes:@{
NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody],
NSForegroundColorAttributeName: [UIColor labelColor]
}];
UIImageSymbolConfiguration *configuration = [UIImageSymbolConfiguration configurationWithFont:[UIFont preferredFontForTextStyle:UIFontTextStyleLargeTitle]];
UIImage *squareImage = [[UIImage systemImageNamed:@"square.fill" withConfiguration:configuration] imageWithTintColor:[UIColor systemBlueColor]];
NSTextAttachment *imageAttachment = [NSTextAttachment textAttachmentWithImage:squareImage];
[string insertAttributedString:[NSAttributedString attributedStringWithAttachment:imageAttachment] atIndex:0];
label.attributedText = string;