我创建了一个基本SwiftUI组件库,其中包括颜色、字体和标准图标的集合。现在,所有组件都引用一个常量文件,用于确定主/辅颜色、标题/段落字体大小和字体等特征,以及其他常量。我希望其他开发人员能够导入这个通用的资源和组件层,并根据他们的项目需求在常量文件中“填空”。导入库后,开发人员还可以使用资源添加更具体的UI组件,以定制自己项目的组件库。
为了获得最大的灵活性,该库既是cocoapod,也是swift软件包。导入包后,是否有方法创建导入模块引用的某种对象或配置?还是我想错了/还有别的办法吗?
通用组件库-->更多特定于项目的组件库-->在团队的项目中使用
常量文件的示例:
public class MyConstants {
// MARK: - Colors
public struct Colors {
public static let primary = Color(MSUColors.purple)
public static let highlight = Color(MSUColors.purpleLighter)
public static let secondary = Color(MSUColors.gold)
public static let disabled = Color(MSUColors.grayLight)
public static let text = Color(MSUColors.grayDarker)
public static let border = Color(MSUColors.grayDark)
public static let background = Color(MSUColors.grayUI)
public static let valid = Color(MSUColors.checkmarkGreen)
public static let error = Color(MSUColors.errorRed)
public static let warning = Color(MSUColors.gold)
}
// MARK: - Icons
public struct Icons {
public static let reviewItems = TaskIcon.BillingSettings
public static let dealerCode = TaskIcon.Customer
public static let setAutoPay = TaskIcon.SetAutoPay
public static let caretLeft = IconImage.caretLine.left?.withRenderingMode(.alwaysTemplate)
public static let deviceLabel = TaskIcon.DeviceLabel
public static let printShippingLabel = TaskIcon.PrintShippingLabel
public static let reviewAgreement = TaskIcon.ReviewAgreement
public static let checkmark = IconImage.Checkmarks.self
public static let managerLogin = IconImage.managerLogin
}
// ..etc for other stuff like fonts and sizes