Last active
August 29, 2015 14:19
-
-
Save y8k/3c84c91ea74053632539 to your computer and use it in GitHub Desktop.
Howto: Set top space to match vertical align attached image with text
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
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