Skip to content

Commit

Permalink
Retina fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarGroth committed Jun 26, 2017
1 parent ff50ecf commit 861ae48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Binary file not shown.
14 changes: 13 additions & 1 deletion FlatButton/FlatButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ open class FlatButton: NSButton, CALayerDelegate {
//containerLayer.backgroundColor = NSColor.blue.withAlphaComponent(0.1).cgColor
//titleLayer.backgroundColor = NSColor.red.withAlphaComponent(0.2).cgColor
titleLayer.delegate = self
if let scale = window?.backingScaleFactor {
titleLayer.contentsScale = scale
}
iconLayer.delegate = self
alternateIconLayer.delegate = self
iconLayer.masksToBounds = true
Expand Down Expand Up @@ -213,7 +216,7 @@ open class FlatButton: NSButton, CALayerDelegate {
break
case .imageLeft:
titleRect.origin.y = round((bounds.height - titleSize.height)/2)
titleRect.origin.x = bounds.width - titleSize.width - 2
titleRect.origin.x = bounds.width - titleSize.width - 6
imageRect.origin.y = round((bounds.height - imageRect.height)/2)
imageRect.origin.x = hSpacing
break
Expand Down Expand Up @@ -355,6 +358,15 @@ open class FlatButton: NSButton, CALayerDelegate {

// MARK: Drawing

override open func viewDidChangeBackingProperties() {
super.viewDidChangeBackingProperties()
if let scale = window?.backingScaleFactor {
titleLayer.contentsScale = scale
layer?.contentsScale = scale
iconLayer.contentsScale = scale
}
}

override open func layer(_ layer: CALayer, shouldInheritContentsScale newScale: CGFloat, from window: NSWindow) -> Bool {
return true
}
Expand Down

0 comments on commit 861ae48

Please sign in to comment.