Reputation: 77596
I'm trying to use the MDCRaisedButton from MaterialComponents, added it as a pod dependency similar to all my other dependencies, but as I try to import it I get a compile error Module MaterialComponents not found
Are there any extra steps I need to take to use this pod?
I noticed in demos they use
pod 'MaterialComponents/Typography', :path => '../../'
What does path do? it gives error when i try to run pod update
Upvotes: 2
Views: 2512
Reputation: 3002
:path
isn't an addition you would need when using MaterialComponents
in your own app, and is used for developing on top of local pods. Have a look here for more info: https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine
In order to use MDCRaisedButton
you would need to initially create a Podfile with pod 'MaterialComponents/Buttons'
inside the chosen app target. If you are using swift as your language of development, I recommend also adding use_frameworks!
. An example Podfile would look like this:
target 'Demo App' do
use_frameworks! # can remove if using Objective-C
pod 'MaterialComponents/Buttons'
end
After that, the import and usage would be:
Swift:
import MaterialComponents.MaterialButtons
let button = MDCRaisedButton()
Objective-C:
#import "MaterialButtons.h"
MDCRaisedButton *button = [[MDCRaisedButton alloc] init];
More info can be found here: https://github.com/material-components/material-components-ios/tree/develop/components/Buttons
As a side note, MDCRaisedButton
will soon be deprecated and theming an MDCButton
using the MDCContainedButtonThemer
is now the best way to get the same raised button style. Therefore the current best practice of doing this is adding to your podfile:
pod 'MaterialComponents/Buttons+Extensions/ButtonThemer'
And then in your implementation:
Swift:
import MaterialComponents.MaterialButtons_ButtonThemer
let buttonScheme = MDCButtonScheme()
let button = MDCButton()
MDCContainedButtonThemer.applyScheme(buttonScheme, to: button)
Objective-C:
#import "MaterialButtons+ButtonThemer.h"
MDCButton *button = [[MDCButton alloc] init];
MDCButtonScheme *buttonScheme = [[MDCButtonScheme alloc] init];
[MDCContainedButtonThemer applyScheme:buttonScheme toButton:button];
More info can be found here: https://github.com/material-components/material-components-ios/blob/develop/components/Buttons/docs/theming.md
The added value of using theming and the scheme is that you can customize the button scheme and have that scheme apply to all your buttons at once. Moreover, if you want a certain color scheme and/or typography scheme throughout your app, the theming now allows these schemes to be applied to all of the material components within your app.
Upvotes: 5