iOS 使用 google MaterialComponents?
iOS using google MaterialComponents?
我正在尝试使用 MaterialComponents 中的 MDCRaisedButton,将其添加为类似于我所有其他依赖项的 pod 依赖项,但是当我尝试导入它时出现编译错误 Module MaterialComponents not found
使用这个 pod 需要额外的步骤吗?
我注意到他们使用的演示
pod 'MaterialComponents/Typography', :path => '../../'
路径有什么作用?当我尝试 运行 pod update
时出现错误
:path
不是您在自己的应用程序中使用 MaterialComponents
时需要的附加项,而是用于在本地 pods 之上进行开发。在这里查看更多信息: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
之后,导入和使用将是:
Swift:
import MaterialComponents.MaterialButtons
let button = MDCRaisedButton()
Objective-C:
#import "MaterialButtons.h"
MDCRaisedButton *button = [[MDCRaisedButton alloc] init];
可以在此处找到更多信息:https://github.com/material-components/material-components-ios/tree/develop/components/Buttons
附带说明一下,MDCRaisedButton
将很快被弃用,使用 MDCContainedButtonThemer
为 MDCButton
设置主题现在是获得相同凸起按钮样式的最佳方式。因此,当前执行此操作的最佳做法是将以下内容添加到您的播客文件中:
pod 'MaterialComponents/Buttons+Extensions/ButtonThemer'
然后在您的实施中:
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];
使用主题和方案的附加值是您可以自定义按钮方案并将该方案立即应用于所有按钮。此外,如果您希望在整个应用程序中使用某种配色方案 and/or 排版方案,主题现在允许将这些方案应用于您应用程序中的所有 material 组件。
我正在尝试使用 MaterialComponents 中的 MDCRaisedButton,将其添加为类似于我所有其他依赖项的 pod 依赖项,但是当我尝试导入它时出现编译错误 Module MaterialComponents not found
使用这个 pod 需要额外的步骤吗?
我注意到他们使用的演示
pod 'MaterialComponents/Typography', :path => '../../'
路径有什么作用?当我尝试 运行 pod update
时出现错误:path
不是您在自己的应用程序中使用 MaterialComponents
时需要的附加项,而是用于在本地 pods 之上进行开发。在这里查看更多信息: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
之后,导入和使用将是:
Swift:
import MaterialComponents.MaterialButtons
let button = MDCRaisedButton()
Objective-C:
#import "MaterialButtons.h"
MDCRaisedButton *button = [[MDCRaisedButton alloc] init];
可以在此处找到更多信息:https://github.com/material-components/material-components-ios/tree/develop/components/Buttons
附带说明一下,MDCRaisedButton
将很快被弃用,使用 MDCContainedButtonThemer
为 MDCButton
设置主题现在是获得相同凸起按钮样式的最佳方式。因此,当前执行此操作的最佳做法是将以下内容添加到您的播客文件中:
pod 'MaterialComponents/Buttons+Extensions/ButtonThemer'
然后在您的实施中:
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];
使用主题和方案的附加值是您可以自定义按钮方案并将该方案立即应用于所有按钮。此外,如果您希望在整个应用程序中使用某种配色方案 and/or 排版方案,主题现在允许将这些方案应用于您应用程序中的所有 material 组件。