Created
May 31, 2021 08:04
-
-
Save kyungpyoda/d16837bc46a6a9f1275c348afab110b3 to your computer and use it in GitHub Desktop.
[Swift] iOS adjust image attachment height of AttributedString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSTextAttachment+setImageHeight.swift | |
// | |
// Created by 홍경표 on 2021/05/31. | |
// | |
import UIKit.NSTextAttachment | |
extension NSTextAttachment { | |
func setImageHeight(to height: CGFloat) { | |
guard let image = image else { return } | |
let ratio = image.size.width / image.size.height | |
bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: ratio * height, height: height) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment