• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

iOS 使用谷歌 MaterialComponents?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 15:58:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

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

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

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

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



Best Answer-推荐答案


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

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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap