YZClasses 0.1.6

YZClasses 0.1.6

Vipul Patel维护。



 
依赖
PhoneNumberKit>= 0
NVActivityIndicatorView>= 0
Kingfisher>= 0
UITextView+Placeholder>= 0
 

YZClasses 0.1.6

  • 作者
  • Vipul Patel (Yudiz Solutions Pvt. Ltd.)

YZClasses

CI Status Version License Platform

特性

  • YZAppConfig 类用于配置 designWidth, designHeight, navigationBarHeight
  • YZCALayerCALayer 的扩展,用于添加或应用 applyShadow, addCornerRadius, addBorder, addGradient
  • YZUIViewUIView 的扩展,用于添加或应用 addCornerRadius, applyShadow, addGradient, addConstraint, addBorder

需求

  • iOS 12.0+
  • Xcode 11+
  • Swift 5.0+

使用

1. YZAppConfig 类

YZAppConfig 用于设置设计者提供的设计 width, height, navigationBarHeight。通过配置设计设置,它将计算 widthRatio, heightRatio, safeAreaInsets

初始化

YZAppConfig.initialise(375, designHeight: 667, navigationBarHeight: 88)

属性

  • YZAppConfig.appDelegate - 使用 UIApplication.shared.delegate! 提供 UIApplicationDeletage 对象。
  • YZAppConfig.navigationBarHeight - 提供设置的导航栏高度。
  • YZAppConfig.designWidth - 提供设置的设计宽度。
  • YZAppConfig.designHeight - 提供设置的设计高度。
  • YZAppConfig.width - 通过 UIScreen.main.bounds.size.width 提供当前运行的 iOS 设备/模拟器的宽度。
  • YZAppConfig.height - 通过 UIScreen.main.bounds.size.height 提供当前运行的 iOS 设备/模拟器的高度。
  • YZAppConfig.widthRatio - 通过计算 width/designWidth 提供宽度比例。
  • YZAppConfig.heightRatio - 通过计算 height/designHeight 提供高度比例。
  • YZAppConfig.safeAreaInsets - 通过 appDelegate.window!!.safeAreaInsets 提供一个 UIEdgeInsets 对象。
  • YZAppConfig.safeAreaInsets - 通过 appDelegate.window!!.safeAreaInsets 提供一个 UIEdgeInsets 对象。

2. YZCALayer

YZCALayerCALayer 的扩展,增加了 addCornerRadiusapplyShadowaddGradientaddConstraintWithSuperViewaddBorderaddDashBorder 等功能。

函数

  • public func addCornerRadiusBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black) - 使用 CAShapeLayer 添加圆角,具有特定的参数。
  • public func applyShadowWith(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = nil, shadowOffset: CGSize = .zero, shadowColor: UIColor, shadowRadius: CGFloat = 3, shadowOpacity:Float = 0) - 使用 CAShapeLayer 绘制阴影,具有特定的参数。
  • public func addBorderBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black, strokeColor: UIColor? = nil, lineWidth: CGFloat = 1) - 使用 CAShapeLayer 绘制边框,具有特定的参数。
  • public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5) - 使用 CAShapeLayer 绘制虚线边框,具有特定的参数。
  • public func addGradient(_ colors: [UIColor], gradientPoint: YZGradientPoint, roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero) - 使用 CAGradientLayer 添加渐变色,具有特定的参数。

3. YZUIView

YZUIView 是对 UIView 的扩展,增加了 addCornerRadiusapplyShadowaddGradientaddConstraintWithSuperViewaddBorderaddDashBorder 等功能。它将内部调用 YZCALayer 函数,根据需要设计 UIView

属性

  • isRound - 使用 @IBInspectable isRound 属性用于在选定的 UIView 上绘制完整的圆形。
  • borderWidth - 使用 @IBInspectable borderWidth 属性用于在选定的 UIView 上绘制边框。
  • borderColor - 使用 @IBInspectable borderColor 属性用于在选定的 UIView 上应用边框颜色。
  • cornerRadius - 使用 @IBInspectable cornerRadius 属性用于在选定的 UIView 上应用圆角。
  • shadowRadius - 使用 @IBInspectable shadowRadius 属性用于定义选定的 UIView 的阴影半径。
  • shadowOpacity - 使用 @IBInspectable shadowOpacity 属性用于定义选定的 UIView 的阴影不透明度。
  • shadowColor - 使用 @IBInspectable shadowColor 属性用于定义选定的 UIView 的阴影颜色。
  • shadowOffset - 使用 @IBInspectable shadowOffset 属性用于定义选定的 UIView 的阴影偏移。
  • zPosition - 使用 @IBInspectable zPosition 属性用于定义 zPosition

函数

  • public func addCornerRadiusBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black) - 用以在 UIView 上添加带有特定参数的圆角。
  • public func applyShadowWith(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = nil, shadowOffset: CGSize = .zero, shadowColor: UIColor, shadowRadius: CGFloat = 3, shadowOpacity:float = 0) - 该函数用于使用特定参数在 UIView 周围绘制阴影。
  • public func addConstraintWithSuperView(_ topConstraint: CGFloat, leadingConstraint: CGFloat, bottomConstraint: CGFloat, trailingConstraint: CGFloat) - 该函数用于向父视图添加约束。
  • public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5) - 使用 CAShapeLayer 绘制虚线边框,具有特定的参数。
  • public func addBorderBy(_ roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero, fillColor: UIColor? = .black, strokeColor: UIColor? = nil, lineWidth: CGFloat = 1) - 该函数用于使用特定参数在 UIView 周围绘制边框。
  • public func addDashBorderBy(_ cornerRadius: CGFloat = .leastNonzeroMagnitude, fillColor: UIColor? = .black, dashColor: UIColor? = nil, dashHeight: CGFloat = 1, dashWidth: CGFloat = 5, spaceBetweenDash: CGFloat = 5) - 该函数用于使用特定参数在 UIView 周围绘制虚线边框。
  • public func addGradient(_ colors: [UIColor], gradientPoint: YZGradientPoint, roundingCorners: UIRectCorner = [.allCorners], cornerRadii: CGSize = .zero) - 该函数用于在 UIView 内部添加渐变色,并带有特定参数。

4. YZArray

YZArray 是对数据类型 Array 的扩展,以执行例如 uniqueElementsremoveElements 操作。

属性

  • uniqueElements - 它将提供唯一的元素数组。

函数

  • public mutating func uniqueElementsInPlace() - 这将用于创建无生成另一个数组的类型的唯一元素数组。
  • public mutating func remove(_ elements: [Element]) - 用于从现有数组中移除一个或多个指定元素。

5. YZURL

YZURLURL 的扩展,提供了以下属性和方法。

属性

  • isFileExists - 用于检查给定的 URL 是否存在文件。
  • convertToData - 用于从给定的文件 URL 生成数据对象。

函数

  • public func deleteFile() - 检查文件是否存在,并从给定的 URL 删除。
  • public func getThumbnailFromVideo() - 用于从给定的视频文件 URL 获取缩略图图像。
  • public func compressVideo(_ outputURL: URL, handler:@escaping (_ exportSession: AVAssetExportSession?, _ compressVideoURL: URL?)-> Void) - 用于压缩给定 URL 的视频。
  • public func getValueForQuery(_ parameter: String) - 用于从给定的查询参数中获取值。

6. YZDictionary

YZDictionaryDictionaryNSDictionary的扩展,提供了以下属性和方法。

属性

  • toJSON - 用于将Dictionary转换为JSON字符串。
  • convertToData - 用于从给定的文件 URL 生成数据对象。

函数

  • public mutating func merge(_ other: Dictionary) - 将现有字典与提供的字典合并。
  • public func getDoubleValue(forKey: String) - 从给定的NSDictionary提供Double类型的值。
  • public func getFloatValue(forKey: String) - 从给定的NSDictionary提供Float类型的值。
  • public func getUIntValue(forKey: String) - 从给定的NSDictionary提供UInt类型的值。
  • public func getIntValue(forKey: String) - 从给定的NSDictionary提供Int类型的值。
  • public func getInt64Value(forKey: String) - 从给定的NSDictionary提供Int64类型的值。
  • public func getInt32Value(forKey: String) - 从给定的NSDictionary提供Int32类型的值。
  • public func getInt16Value(forKey: String) - 从给定的NSDictionary提供Int16类型的值。
  • public func getInt8Value(forKey: String) - 从给定的 NSDictionary提供Int8类型的值。
  • public func getStringValue(forKey: String) - 从给定的NSDictionary提供String类型的值。
  • public func getBooleanValue(forKey: String) - 该函数将从给定的 NSDictionary 中获取 Bool 类型的值。

7. YZString

YZString 文件使用 StringNSMutableAttributedStringNSAttributedString 的扩展来执行一些字符串处理操作,并提供以下属性和函数。

属性

  • isEmailAddressValid - 用于检查电子邮件地址是否有效,它将返回 Bool 值。
  • trimmedString - 用于去除空白字符和换行符,它将返回 String 值。
  • isOnlyNumericValue - 用于检查给定的字符串是否有数值,它将返回 Bool 值。
  • toDouble - 用于将 String 类型的值转换为 Double 类型的值。
  • toFloat - 用于将 String 类型的值转换为 toFloat 类型的值。
  • toInt - 用于将 String 类型的值转换为 toInt 类型的值。
  • toInt64 - 用于将 String 类型的值转换为 toInt64 类型的值。
  • toInt32 - 用于将 String 类型的值转换为 toInt32 类型的值。
  • toInt16 - 用于将 String 类型的值转换为 toInt16 类型的值。
  • toInt8 - 用于将 String 类型的值转换为 toInt8 类型的值。
  • camelCaseLetter - 用于将字符串显示为驼峰式字母,它将返回 String 类型的值。
  • htmlToAttributedString - 用于将 HTML 转换为富文本。
  • htmlToString - 用于将 HTML 转换为字符串。
  • initialCharactersFromWord - 用于从单词中提取字符以显示为用户头像。
  • isPhoneNumberValid - 用于检查电话号码是否有效。它将返回 布尔 值。
  • adjustedNationalNumber - 如果需要,通过添加前导零来调整国家级号码以供显示。用于基本格式化功能。

函数

  • public func contains(_ find: String) - 用于检查给定字符串是否包含。
  • public func isEqual(_ otherString: String) - 用于比较两个字符串。
  • public func singleLineHeightFor(_ font: UIFont) - 用于基于提供的字体计算给定字符串的单行高度。
  • public func heightForFixed(_ width: CGFloat, font: UIFont) - 用于根据固定宽度计算给定字符串的高度。
  • public func widthForFixed(_ height: CGFloat, font: UIFont) - 用于根据固定高度计算给定字符串的宽度。
  • public func capitalizingFirstLetter() - 用于将给定字符串或单词的首字母大写。
  • public func strikeThroughLine(_ color: UIColor, textFont: UIFont, foregroundColor: UIColor) - 用于在给定字符串上绘制删除线。它将内部调用 NSMutableAttributedString 函数。
  • public func addVertical(_ lineSpacing: CGFloat, alignment: NSTextAlignment, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor) - 用于根据给定的参数在给定字符串上添加垂直间距。它将内部调用 NSMutableAttributedString 函数。
  • public func addCharacters(_ spacing: CGFloat, alignment: NSTextAlignment = .natural, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor) - 用于根据给定参数在给定字符之间添加空间。它将内部调用 NSMutableAttributedString 函数。
  • public func setString(_ alignment: NSTextAlignment = .natural, textFont: UIFont? = nil, foregroundColor: UIColor? = nil) - 用于根据给定参数设置字符串对齐方式、字体和前景色。它将内部调用 NSMutableAttributedString 函数。
  • public func addCharacters(_ shadowColor: UIColor, shadowBlurRadius: CGFloat, shadowOffset: CGSize = .zero, textFont: UIFont, foregroundColor: UIColor) - 用于将阴影效果应用于字符。

8. YZButtons

YZButtons 文件包含多个 UIButton 类和 UIButton 扩展,提供了以下类和函数。

  • YZParentWidthBTN - 当您想要设计支持多个设备的 UIButton 并应用 widthRatio 时,可以用于此。
  • YZParentHeightBTN - 当您想要设计支持多个设备的 UIButton 并应用 heightRatio 时,可以用于此。

函数

  • public func setAttributed(_ texts: [String], attributes: [[NSAttributedString.Key : Any]], state: UIControl.State) - 用于设置文本及其属性,根据给定的参数来设置。它将内联调用 NSAttributedString 函数。

9. YZLabels

YZLabels 文件包含多个 UILabel 类以及 UILabel 的扩展,提供了以下类、属性和函数。

  • YZParentWidthLBL - 当你需要按照多种设备支持设计 UILabel 并应用 widthRatio 时使用。
  • YZParentHeightLBL - 当你需要按照多种设备支持设计 UILabel 并应用 heightRatio 时使用。

属性

  • isTruncated - 用于检查给定的标签是否被截断。它将返回布尔类型值。

函数

  • public func addCharacters(_ spacing: CGFloat, alignment: NSTextAlignment = .natural, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor) - 用于以给定的参数在给定的字符之间添加间隔。它将内部调用 String 函数。
  • public func setAttributed(_ texts: [String], attributes: [[NSAttributedString.Key : AnyObject]]) - 用于添加文本及其属性。
  • public func setVertical(_ lineSpacing: CGFloat, alignment: NSTextAlignment, lineBreakMode: NSLineBreakMode = .byTruncatingTail, textFont: UIFont, foregroundColor: UIColor) - 用于根据给定的参数在给定的文本上添加垂直空白行。它将内部调用 String 函数。
  • public func addStrikeThroughLine(_ color: UIColor, textFont: UIFont, foregroundColor: UIColor) - 用于在给定文本上绘制删除线。它将内部调用 String 函数。

10. YZTextViews

YZTextViews 文件包含多个 UITextView 类和 UITextView 的扩展,提供了以下类、属性、协议和函数。

  • YZParentWidthTV - 当您想要以支持多个设备的方式设计 UITextView 并应用 widthRatio 时使用。
  • YZParentHeightTV - 当您想要以支持多个设备的方式设计 UITextView 并应用 heightRatio 时使用。
  • YZWithoutInsetTV - 当您想要设计没有额外边距或填充的 UITextView 时使用。
  • YZLinkableTV - 当您想要获取 UIDataDetectorTypes 的值时使用。

协议

  • YZLinkableTVDelegate - 当您想要获取 UIDataDetectorTypes 的值时使用。

函数

  • public func newHeightUsing(_ baseHeight: CGFloat) - 计算新的 textview 高度(基于内容)是否大于基本高度。

11. YZTextFields

YZTextFields 文件包含多个 UITextField 类及其扩展,提供了以下类和函数。

  • YZParentWidthTF - 当您想要以多设备支持设计 UITextField 并应用 widthRatio 时使用。
  • YZParentHeightTF - 当您想要以多设备支持设计 UITextField 并应用 heightRatio 时使用。
  • YZParentPaddingTF - 用于使用 UIEdgeInsets 设置 TextRect、PlaceHolderRect 和 EditingRect 的填充。

函数

  • public func addInputAccessory(_ text: String, textFont: UIFont, tintColor: UIColor? = nil, rect: CGRect = .zero) - 用于向 UITextField 添加输入工具栏视图。
  • public func fixCaretPosition() - 用于通过删除尾随空格将光标移动到正确的位置。
  • public func setAttributed(_ placeHolder: String?, color: UIColor, font: UIFont) - 用于设置带有给定参数的属性占位符。

12. YZColor

YZColor 文件包含 UIColor 扩展,它提供了以下功能。

函数

  • public convenience init(_ hexaValue: String, alpha: CGFloat = 1.0) - 该方法用于从给定的十六进制值和透明度值初始化 UIColor 对象。
  • public static func initWith(_ red: Int, green: Int, blue: Int, alpha: CGFloat) - 该方法用于从给定的 RGBA 值初始化 UIColor 对象。
  • public func brightenedBy(_ factor: CGFloat) - 该方法用于向现有颜色添加亮色效果。

13. YZImage

YZImage 文件包含 UIImage 扩展,提供以下属性和函数。

属性

  • fixedOrientation - 用于固定给定图像的方位。

函数

  • public static func generateQRCodeFrom(_ string: String) - 用于从给定字符串生成 QR码图像
  • public static func getSquareImage() - 用于生成方形图像。
  • public func resizeImageWith(_ width: CGFloat, height: CGFloat) - 用于根据给定参数调整图像大小。
  • public func scaleTo(_ newSize: CGSize, isAspectFill: Bool = true) - 用于将图像缩放以适应指定尺寸范围内。并保持宽高比。
  • public func scaleAndManageAspectRatio(_ width: CGFloat) - 用于降低图像分辨率并保持宽高比。

14. YZIndexPath

YZIndexPath 文件包含 IndexPath 扩展,它提供了一系列函数。

函数

  • public static func indexPathForCellContaining(_ view: UIView, tableView: UITableView) - 该方法用于从 UITableView 获取 IndexPath
  • public static func indexPathForCellContaining(_ view: UIView, collectionView: UICollectionView) - 该方法用于从 UICollectionView 获取 IndexPath

15. YZViewController

YZViewController 文件包含多个 UIWindowUIViewControllerUIApplication 扩展,提供了以下属性和方法。

属性

  • currentVisibleViewController - 用于获取 UIWindowUIViewControllerUIApplication 的当前可见 UIViewController

函数

  • public static func getCurrentVisibleVCFor(_ vc: UIViewController) - 用于获取给定 UIViewController 的当前可见 UIViewController

16. YZActivityIndicatorView

使用图像初始化自定义指示器视图的 YZActivityIndicatorView 类,具有以下属性和函数。

属性

  • isAnimating - 它将返回一个 Bool 值来检查是否正在动画中。
  • hidesWhenStopped - 它用于设置属性,以便在停止动画时隐藏指示器视图。

函数

  • public func startAnimating() - 用于启动动画。
  • public func stopAnimating() - 用于停止动画。

17. YZConstrainedViews

YZConstrainedViews 文件包含多个类,用于设置应用程序的父类,提供以下类。

协议

  • YZUserTapDelegate - 用于获取在 tableCell、collectionCell 和 headerFooter 视图上对文本的点击事件。
  • YZTextFieldDelegate - 用于获取 UITextField 事件。

  • YZParentControl - 是 UIControl 的子类,用于设置父类。
  • YZParentCVC - 是 UICollectionViewCell 的子类,用于设置父类。
  • YZParentCRV - 是 UICollectionReusableView 的子类,用于设置父类。
  • YZParentHFV - 是 UITableViewHeaderFooterView 的子类,用于设置父类。
  • YZParentTVC - 是 UITableViewCell 的子类,用于设置父类。
  • YZParentView - 是 UIView 的子类,用于设置父类。

17. YZLinkLabel

YZLinkLabel 类用于检测指定字符串中的提及、哈希标签或网址,并提供以下属性和方法。

属性

  • arrOfHashTags - 它用于获取哈希标签的数量。
  • arrOfMentions - 它用于获取提及标签的数量。
  • arrOfURLs - 它用于获取网址的数量。
  • delegate - 用于设置委托以获取事件。

函数

  • public func set(_ attributedString: NSAttributedString, linebreak : NSLineBreakMode = .byTruncatingTail) - 用于设置属性文本。

18. YZPermission

YZPermission 类用于检查如相机访问、照片库访问等权限,具有以下功能。

函数

  • public func cameraAccess(permissionWithStatus block: @escaping PermissionStatus) - 用于检查相机访问权限。
  • public func photoLibraryAccess(permissionWithStatus block: @escaping PermissionStatus) - 用于检查照片库访问权限。
  • public func locationAccess(permissionWithStatus block: @escaping PermissionStatus) - 用于检查位置访问权限。

19. YZNumbers

YZNumbers 类用于操纵一些与数字相关的操作,以下是一些属性和函数。

属性

  • suffixNumber - 它用于将 Double 值转换为以 K(千)和 M(百万)形式表示的 String

函数

  • public mutating func roundTo(_ places: Int) - 它用于将 Double 值四舍五入到指定的小数位。

安装

YZClasses可通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中

pod 'YZClasses', '~> 0.1.6'

作者

Vispu Patel (Yudiz Solutions Pvt. Ltd.), [email protected]

许可证

YZClasses 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。