Buttons is a collection of Material Design buttons, including a flat button, a raised button and a floating action button.
The flat button does not have its own background color and does not raise when touched. Use a flat button in most situations requiring a button.
The raised button has its own background color. It floats above its parent slightly, and raises briefly when touched. A raised button should be used when a flat button would get lost among other UI elements on the screen.
The floating action button is circular, floats a considerable amount above its parent, has its own background color, and also raises briefly when touched. Only use a floating action button for the main action of a screen.
Flat button, raised button and floating action buttons all inherit from the same MDCButton class. You should not directly instantiate an MDCButton object.
- Xcode 7.0 or higher.
- iOS SDK version 7.0 or higher.
To add this component to your Xcode project using CocoaPods, add the following to your Podfile
:
pod 'MaterialComponents/Buttons'
Then, run the following command:
pod install
Before using a Button, you'll need to import the button you want to use:
import MaterialComponents
#import "MaterialButtons.h"
All buttons display animated ink splashes when the user interacts with the button.
For non-flat buttons, the background color is determined from the enabled, disabled-light, and disabled-dark background color properties. Flat buttons have a transparent background.
When disabled, Material buttons take on a specific semi-transparent appearance which depends on whether the button is on a light background or a dark background.
Set the title color of the button to have an accessible contrast ratio with the button's background
color. The caller is responsible for setting (and updating, if necessary) the button's
underlyingColor
property for flat buttons.
All buttons set the exclusiveTouch
property to YES by default, which prevents users from
simultaneously interacting with a button and other UI elements.
let flatButton = MDCFlatButton()
flatButton.customTitleColor = UIColor.gray
flatButton.setTitle("Tap me", for: .normal)
flatButton.sizeToFit()
flatButton.addTarget(self, action: "tap:", for: .touchUpInside)
self.view.addSubview(flatButton)
MDCFlatButton *flatButton = [MDCFlatButton new];
[flatButton setTitle:@"Tap Me" forState:UIControlStateNormal];
[flatButton setCustomTitleColor:[UIColor grayColor]];
[flatButton sizeToFit];
[flatButton addTarget:self
action:@selector(tap:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:flatButton];
Create a Raised button and change its default elevation. The default elevation for raised buttons in resting state is 2 dp.
let raisedButton = MDCRaisedButton()
// See https://material.io/guidelines/what-is-material/elevation-shadows.html
raisedButton.setElevation(4, for: .normal)
raisedButton.setTitle("Tap Me Too", for: .normal)
raisedButton.sizeToFit()
raisedButton.addTarget(self, action: "tap:", for: .touchUpInside)
self.view.addSubview(raisedButton)
MDCRaisedButton *raisedButton = [MDCRaisedButton new];
// See https://material.io/guidelines/what-is-material/elevation-shadows.html
[raisedButton setElevation:4.0f forState:UIControlStateNormal];
[raisedButton setTitle:@"Tap Me Too" forState:UIControlStateNormal];
[raisedButton sizeToFit];
[raisedButton addTarget:self action:@selector(didTap:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:raisedButton];
let floatingButton = MDCFloatingButton()
floatingButton.setTitle("+", for: .normal)
floatingButton.sizeToFit()
floatingButton.addTarget(self, action: "tap:", for: .touchUpInside)
self.view.addSubview(floatingButton)
MDCFloatingButton *floatingButton = [MDCFloatingButton new];
[floatingButton setTitle:@"+" forState:UIControlStateNormal];
[floatingButton sizeToFit];
[floatingButton addTarget:self
action:@selector(didTap:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:floatingButton];