gpt4 book ai didi

iOS 使用谷歌 MaterialComponents?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:36:10 27 4
gpt4 key购买 nike

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

使用此 pod 我需要采取任何额外步骤吗?

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

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

路径有什么作用?当我尝试运行 pod update 时出现错误

最佳答案

: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

之后,导入和使用将是:

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 现在是获得相同效果的最佳方式凸起的按钮样式。因此,当前执行此操作的最佳做​​法是将以下内容添加到您的 podfile:

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];

可在此处找到更多信息:https://github.com/material-components/material-components-ios/blob/develop/components/Buttons/docs/theming.md

使用主题和方案的附加值是您可以自定义按钮方案并让该方案立即应用于所有按钮。此外,如果您想要在整个应用程序中使用特定的配色方案和/或排版方案,主题现在允许将这些方案应用于您应用程序中的所有 Material 组件。

关于iOS 使用谷歌 MaterialComponents?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51120732/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com