Skip to content

Instantly share code, notes, and snippets.

@y8k
Last active August 29, 2015 14:19
Show Gist options
  • Save y8k/3c84c91ea74053632539 to your computer and use it in GitHub Desktop.
Save y8k/3c84c91ea74053632539 to your computer and use it in GitHub Desktop.
Howto: Set top space to match vertical align attached image with text
class TDTextAttachment: NSTextAttachment {
var topSpace: Float = 0.0
convenience init(image: UIImage, topSpace: Float = 0.0) {
self.init()
self.image = image
self.topSpace = 0.0
}
override func attachmentBoundsForTextContainer(textContainer: NSTextContainer, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect {
let imageSize = image!.size
return CGRect(x: 0.0, y: CGFloat(topSpace), width: imageSize.width, height: imageSize.height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment