【问题标题】:iOS using google MaterialComponents?iOS 使用谷歌 MaterialComponents?
【发布时间】:2018-07-01 05:45:15
【问题描述】:

我正在尝试使用 MaterialComponents 中的 MDCRaisedButton,将其添加为类似于我所有其他依赖项的 pod 依赖项,但是当我尝试导入它时出现编译错误 Module MaterialComponents not found

我需要采取什么额外的步骤才能使用这个吊舱吗?

我在他们使用的演示中注意到

  pod 'MaterialComponents/Typography', :path => '../../'

路径是做什么的?当我尝试运行 pod update 时出现错误

【问题讨论】:

  • 你能给我们看看你的 podfile 吗?您是否在 podfile 顶部添加了源 URL?

标签: ios material-components


【解决方案1】:

: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 很快将被弃用,使用MDCContainedButtonThemerMDCButton 设置主题现在是获得相同凸起按钮样式的最佳方式。因此,当前执行此操作的最佳实践是添加到您的 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

使用主题和方案的附加价值是您可以自定义按钮方案并将该方案一次应用于所有按钮。此外,如果您希望在整个应用中使用特定的配色方案和/或排版方案,现在主题化允许将这些方案应用于应用中的所有材质组件。

【讨论】:

  • 不起作用,no such module 错误。除 MaterialComponents 之外的所有其他 pod 都可以使用
  • 我的 pod 文件中缺少 use_frameworks!,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-02
  • 2013-07-13
  • 2017-01-18
相关资源
最近更新 更多