:path 不是在您自己的应用程序中使用 MaterialComponents 时需要的附加项,它用于在本地 pod 之上进行开发。在这里查看更多信息:https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine
为了使用MDCRaisedButton,您首先需要在所选应用目标内创建一个带有pod 'MaterialComponents/Buttons' 的Podfile。如果您使用 swift 作为您的开发语言,我建议您也添加use_frameworks!。 Podfile 示例如下所示:
target 'Demo App' do
use_frameworks! # can remove if using Objective-C
pod 'MaterialComponents/Buttons'
end
之后,导入和使用将是:
斯威夫特:
import MaterialComponents.MaterialButtons
let button = MDCRaisedButton()
目标-C:
#import "MaterialButtons.h"
MDCRaisedButton *button = [[MDCRaisedButton alloc] init];
更多信息可以在这里找到:https://github.com/material-components/material-components-ios/tree/develop/components/Buttons
附带说明,MDCRaisedButton 很快将被弃用,使用MDCContainedButtonThemer 为MDCButton 设置主题现在是获得相同凸起按钮样式的最佳方式。因此,当前执行此操作的最佳实践是添加到您的 podfile:
pod 'MaterialComponents/Buttons+Extensions/ButtonThemer'
然后在你的实现中:
斯威夫特:
import MaterialComponents.MaterialButtons_ButtonThemer
let buttonScheme = MDCButtonScheme()
let button = MDCButton()
MDCContainedButtonThemer.applyScheme(buttonScheme, to: button)
目标-C:
#import "MaterialButtons+ButtonThemer.h"
MDCButton *button = [[MDCButton alloc] init];
MDCButtonScheme *buttonScheme = [[MDCButtonScheme alloc] init];
[MDCContainedButtonThemer applyScheme:buttonScheme toButton:button];
更多信息可以在这里找到:https://github.com/material-components/material-components-ios/blob/develop/components/Buttons/docs/theming.md
使用主题和方案的附加价值是您可以自定义按钮方案并将该方案一次应用于所有按钮。此外,如果您希望在整个应用中使用特定的配色方案和/或排版方案,现在主题化允许将这些方案应用于应用中的所有材质组件。