Created
July 3, 2018 13:20
-
-
Save mmuszynski/c062df8711981d75c3369512b697a83a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CenteredClipView: NSClipView { | |
override func constrainBoundsRect(_ proposedBounds: NSRect) -> NSRect { | |
var rect = super.constrainBoundsRect(proposedBounds) | |
if let containerView = self.documentView { | |
if (rect.size.width > containerView.frame.size.width) { | |
rect.origin.x = (containerView.frame.width - rect.width) / 2 | |
} | |
if(rect.size.height > containerView.frame.size.height) { | |
rect.origin.y = -(containerView.frame.height - rect.height) / 2 | |
} | |
} | |
return rect | |
} | |
} | |
class ImageWell: NSImageView { | |
override var image: NSImage? { | |
didSet { | |
self.frame.size = image?.size ?? self.frame.size | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment