Skip to content

Commit

Permalink
Title/image position from IB
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarGroth committed Mar 9, 2017
1 parent c6dc91d commit 2121f81
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
2 changes: 1 addition & 1 deletion FlatButton.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'FlatButton'
s.version = '1.1'
s.version = '1.1.1'
s.summary = 'Layer based NSButton with Interface Builder styling options'
s.homepage = 'https://github.com/OskarGroth/FlatButton'
s.license = {
Expand Down
4 changes: 0 additions & 4 deletions FlatButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
75670D831DB7A6BF00F6EA18 /* FlatButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 75670D811DB7A6BF00F6EA18 /* FlatButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
75670D941DB7AEF400F6EA18 /* FlatButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75935E3A1D534DD90069AF86 /* FlatButton.swift */; };
75820B261D5A5B2400B98872 /* close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 75820B251D5A5B2400B98872 /* close@2x.png */; };
75935E2E1D534A1A0069AF86 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75935E2D1D534A1A0069AF86 /* AppDelegate.swift */; };
75935E331D534A1A0069AF86 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 75935E311D534A1A0069AF86 /* MainMenu.xib */; };
75935E3C1D534DD90069AF86 /* FlatButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75935E3A1D534DD90069AF86 /* FlatButton.swift */; };
Expand All @@ -19,7 +18,6 @@
75670D7F1DB7A6BF00F6EA18 /* FlatButton.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlatButton.framework; sourceTree = BUILT_PRODUCTS_DIR; };
75670D811DB7A6BF00F6EA18 /* FlatButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FlatButton.h; sourceTree = "<group>"; };
75670D821DB7A6BF00F6EA18 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
75820B251D5A5B2400B98872 /* close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close@2x.png"; sourceTree = "<group>"; };
75935E2A1D534A1A0069AF86 /* FlatButton-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FlatButton-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
75935E2D1D534A1A0069AF86 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
75935E321D534A1A0069AF86 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -78,7 +76,6 @@
children = (
75935E2D1D534A1A0069AF86 /* AppDelegate.swift */,
75935E311D534A1A0069AF86 /* MainMenu.xib */,
75820B251D5A5B2400B98872 /* close@2x.png */,
75935E341D534A1A0069AF86 /* Info.plist */,
);
name = "FlatButton-macOS";
Expand Down Expand Up @@ -190,7 +187,6 @@
buildActionMask = 2147483647;
files = (
75935E331D534A1A0069AF86 /* MainMenu.xib in Resources */,
75820B261D5A5B2400B98872 /* close@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,21 @@
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FlatButton/FlatButton.swift"
timestampString = "510778358.940484"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "158"
endingLineNumber = "158"
landmarkName = "setupTitle()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
45 changes: 43 additions & 2 deletions FlatButton/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iGx-ll-GI1" customClass="FlatButton" customModule="FlatButton_Example" customModuleProvider="target">
<rect key="frame" x="349" y="170" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="NSBookmarksTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ywI-Fd-2ZO">
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="NSBookmarksTemplate" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ywI-Fd-2ZO">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
Expand Down Expand Up @@ -780,7 +780,7 @@
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="E4h-Kk-N40" customClass="FlatButton" customModule="FlatButton_Example" customModuleProvider="target">
<rect key="frame" x="106" y="260" width="120" height="38"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" imagePosition="above" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="DJi-tN-P3q">
<buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="DJi-tN-P3q">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
Expand Down Expand Up @@ -818,6 +818,47 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="cf2-SW-dok" customClass="FlatButton" customModule="FlatButton_Example" customModuleProvider="target">
<rect key="frame" x="188" y="92" width="120" height="38"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="NSActionTemplate" imagePosition="below" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="FDg-tb-gzV">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="4"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
<real key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="buttonColor">
<color key="value" white="1" alpha="0.0" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="activeButtonColor">
<color key="value" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="iconColor">
<color key="value" red="0.2392156869" green="0.67450982329999998" blue="0.96862745289999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="activeIconColor">
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="textColor">
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="activeTextColor">
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="momentary" value="NO"/>
<userDefinedRuntimeAttribute type="number" keyPath="offAnimationDuration">
<real key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="onAnimationDuration">
<real key="value" value="0.10000000000000001"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</button>
</subviews>
</view>
<point key="canvasLocation" x="61.5" y="-63"/>
Expand Down
23 changes: 21 additions & 2 deletions FlatButton/FlatButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,27 @@ public class FlatButton: NSButton, CALayerDelegate {
var titleRect = cell!.titleRect(forBounds: bounds)
let attributes = [NSFontAttributeName: font]
let size = title.size(withAttributes: attributes)
titleRect.origin.x = round((bounds.width - size.width)/2)
titleRect.origin.y = round((bounds.height - size.height)/2)
switch imagePosition {
case .imageAbove:
titleRect.origin.y = bounds.height - size.height - 1
titleRect.origin.x = round((bounds.width - size.width)/2)
break
case .imageBelow:
titleRect.origin.y = 1
titleRect.origin.x = round((bounds.width - size.width)/2)
break
case .imageLeft:
titleRect.origin.y = round((bounds.width - size.width)/2)
titleRect.origin.x = bounds.width - size.width + 1
break
case .imageRight:
titleRect.origin.y = round((bounds.width - size.width)/2)
titleRect.origin.x = 1
break
default:
titleRect.origin.y = round((bounds.height - size.height)/2)
titleRect.origin.x = round((bounds.width - size.width)/2)
}
titleLayer.frame = titleRect
titleLayer.string = title
titleLayer.font = font
Expand Down
Binary file removed FlatButton/close@2x.png
Binary file not shown.

0 comments on commit 2121f81

Please sign in to comment.