A rectangular UIButton that transform itself into a circle (animated), with a built-in Activity indicator. Written entirely in Swift.
Download/Clone the project. Open it with Xcode. Go in the Main.Storyboard File Select a Button. Now you can play/custom it with the attributes Inspector. Then Just Launch It (On simulator Or Device).
- Drop the
LMPolymorphicButton.swift
into your project - There is no step Two.
- Highly and easily customizable
- Built with and for Autolayout
- Made with love
- Needs AutoLayout.
I will present here a simple usage case From Storyboard/Inteface builder. there is a lot of way to use this component. 1 Create a UIView 2 Inside that UIView Put a UIButton with these constraints:
- Same Width (priority 750)
- Same Height (priority 750)
- Center Vertically
- Center Horizontally 3 Change the Class of that UIButton to LMPolymorphicButton In the identity Inspector
That's It.
Now from the code you can just call the startActivity Method:
myAwesomeButton.startActivity()
myAwesomeButton.stopActivity()
LMPolymorphicButton Uses Autolayout's.
There are two animations, the CornerRadius Animation (To transform it into a Circle) and the AspectRatio Constraint’s Animation (to set the width equal to the height, circle/square). LMPolymorphic add programttically a constraints to Itself: AspectRatio 1:1. When I Need to collapse It I change the priority Of this constraint to 800(this value must be greater than the « Same Width » and « Same Height » priority. And when I need to expand it I change the priority from 800 to 200. I Just Animate this priority Change.
The CornerRadius Animation is a simple CABasicAnimation.
So LMPOlymorphicButton Requires AutoLayout To works.
Fully Customizable From Storyboard.
Pull requests are welcome Just Open an Issue Or Make A pull Request to add It here.
Just open an Issue.