FortnightUtils 0.1.0

FortnightUtils 0.1.0

Fortnight Studio 维护。



FortnightUtils

Version License Platform

Banner

描述

FortnightUtils 是一个功能库,包含函数和变量,可让您快速以编程方式构建应用程序。该库的目的是在无需担心创建自己的辅助文件和扩展的情况下,使用这些组件构建生产应用程序。

特性

示例

要运行示例项目,请先克隆仓库,然后在 Example 目录中运行 pod install

需求

该项目需要Xcode 10+,支持iOS 9.3+的系统,以及Cocoapods。

安装

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

pod 'FortnightUtils'

使用

导入

import FortnightUtils

UIColor

RGB颜色
let RGBColor = UIColor(r: 255, g: 255, b: 255, a: 1)
HEX颜色
let HEXColor = UIColor(hex: "#d73a49", alpha: 1)

UIButton

let button = UIButton.systemButton(title: "Title", image: nil, titleColor: .red, font: nil, target: self, selector: #selector(buttonSelector))

UILabel

设置字符间距
myLabel.setCharactersSpacing(value: 2.5)
设置行高
myLabel.setLineHeight(value: 0.5)
// or
myLabel.setLineHeight(value: 0.5, lineBreakMode: byWordWrapping, alignment: .center)

lineBreakMode 和 alignment 是可选参数。

UITextView

设置字符间距
myTextView.setCharactersSpacing(value: 2.5)
设置行高
myTextView.setLineHeight(value: 0.5)
// or
myTextView.setLineHeight(value: 0.5, alignment: .center)

alignment 是可选参数。

UIView

填充父视图
myView.fillSuperView()
居中对齐到父视图
myView.anchorCenterSuperview()
在父视图Y轴中心对齐
myView.anchorCenterYToSuperview()
在父视图X轴中心对齐
myView.anchorCenterXToSuperview()
锚定UIView
// Before
myView.topAnchor.constraint(equalTo: view.topAnchor, constant: 10).isActive = true
myView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true
myView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 10).isActive = true
myView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 10).isActive = true

// After
myView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, topConstant: 10, leftConstant: 10, bottomConstant: 10, rightConstant: 10, widthConstant: 0, heightConstant: 0)

UIViewController

let childViewController = ChildViewController()

self.add(childViewController) // Add child view controller
childViewController.remove() // Remove child view controller

UserDefaults

let isFirstLaunch = UserDefaults.isAppFirstLaunch
UserDefaults.setAppFirstLaunch()

缓存 ImageView

初始化器
let cachedImageView = CachedImageView(cornerRadius: 5, emptyImage: emptyImage)
let cachedImageView = CachedImageView(cornerRadius: 5, tapCallback: callback)
let cachedImageView = CachedImageView(tapCallback: callback)
异步加载图片
cachedImageView.loadImage(urlString: "url", completion: {
    // Completion block
})

作者

Fortnight Studio, [email protected]

许可证

FortnightUtils 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。