To run the example project, clone the repo. No need to run any carthage commands. Framework is included in project 😀
To integrate JPShrinkingButton into your Xcode project using Carthage, specify it in your Cartfile:
github julp04/JPShrinkingButton
-
Run
carthage update
-
A
Cartfile.resolved
file and aCarthage
directory will appear in the same directory where your.xcodeproj
or.xcworkspace
is -
Drag the built
.framework
binaries fromCarthage/Build/<platform>
into your application’s Xcode project. -
If you are using Carthage for an application, follow the remaining steps, otherwise stop here.
-
On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex:
/bin/sh
), add the following contents to the script area below the shell:/usr/local/bin/carthage copy-frameworks
-
Add the paths to the frameworks you want to use under “Input Files". For example:
$(SRCROOT)/Carthage/Build/iOS/JPShrinkingButton.framework
-
Add the paths to the copied frameworks to the “Output Files”. For example:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/JPShrinkingButton.framework
Works just like any normal UIButton where you can set titles, images, etc.
button = JPShrinkingButton(frame: buttonFrame)
button?.setTitle("Send Message", for: .normal)
button?.setImage(#imageLiteral(resourceName: "message.png"), for: .normal)
button?.tintColor = .white
button?.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1)
button?.addTarget(self, action: #selector(showAlert), for: .touchUpInside)
view.addSubview(button!)
There are two methods for animating the button: Expand and shrink
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if velocity.y >= 0.6 {
button?.shrink()
return
}
if velocity.y <= -0.6 {
button?.expand()
return
}
}
julp04, julpanucci@gmail.com
JPShrinkingButton is available under the MIT license. See the LICENSE file for more info.