how to resize an image or done as a NSAttributedString NSTextAttachment (or set its initital size)
You should set bounds form attachment to resize image like this: attachment.bounds = CGRectMake(0, 0, yourImgWidth, yourImgHeight)
You should set bounds form attachment to resize image like this: attachment.bounds = CGRectMake(0, 0, yourImgWidth, yourImgHeight)
It seems that there’s a bug in UIKit. There’s a workaround for that ;] For some reason you need to append empty space before image attachment to make it work properly with UIImageRenderingModeAlwaysTemplate. So your snippet would look like that (mine is in ObjC): – (NSAttributedString *)attributedStringWithValue:(NSString *)string image:(UIImage *)image { NSTextAttachment *attachment = [[NSTextAttachment … Read more
You can use the capHeight of the font. Objective-C NSTextAttachment *icon = [[NSTextAttachment alloc] init]; UIImage *iconImage = [UIImage imageNamed:@”icon.png”]; [icon setBounds:CGRectMake(0, roundf(titleFont.capHeight – iconImage.size.height)/2.f, iconImage.size.width, iconImage.size.height)]; [icon setImage:iconImage]; NSAttributedString *iconString = [NSAttributedString attributedStringWithAttachment:icon]; [titleText appendAttributedString:iconString]; Swift let iconImage = UIImage(named: “icon.png”)! var icon = NSTextAttachment() icon.bounds = CGRect(x: 0, y: (titleFont.capHeight – iconImage.size.height).rounded() / … Read more