Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyungpyoda/d16837bc46a6a9f1275c348afab110b3 to your computer and use it in GitHub Desktop.
Save kyungpyoda/d16837bc46a6a9f1275c348afab110b3 to your computer and use it in GitHub Desktop.
[Swift] iOS adjust image attachment height of AttributedString
//
// 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