TSwiftHelper
TSwiftHelper 是一个用 Swift 编写的 iOS 库,可以帮助用户在开发中获得许多有用的扩展函数。
要求
- iOS 11.0+
- Swift 5
安装
CocoaPods
从TSwiftHelper 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'TSwiftHelper'
其次,将 TProgressHUD
安装到您的项目中
pod install
手动安装
只需将 TSwiftHelper/TSwiftHelper
文件夹中的文件拖放到您的项目中即可
Swift 包
TProgressHUD
为 Swift 5 设计。要依赖日志 API 包,您需要在您的 Package.swift
文件中声明依赖项
.package(url: "https://github.com/fanta1ty/TSwiftHelper.git", brand: "master"),
使用方法
LabelHelper
let testLb = LabelHelper(style: LabelStyle(backgroundColor: .Clear,
borderColor: .Clear,
borderWidth: 0,
corderRadius: 0,
textColor: .Black,
textFont: .regular(size: 16),
textAlignment: .center,
numberOfLines: 1,
isHidden: false),
text: "Your text")
ButtonHelper
let testBtn = ButtonHelper(style: ButtonStyle(backgroundColor: .Blue,
borderColor: .Black,
borderWidth: 1,
corderRadius: 8,
textColor: .White,
textFont: .regular(size: 16),
clipsToBounds: true,
isHidden: false,
isUserInteractionEnabled: true),
title: "Button Title",
normalImage: "Button Image".uiImage,
selectedImage: "Button Image when selected".uiImage)
// uiImage() is a function to set image for components instead of using UIimage(named: "Image Name")
TextFieldHelper
let testTextfield = TextFieldHelper(style: TextFieldStyle(backgroundColor: .Clear,
borderColor: .Black,
borderWidth: 1,
corderRadius: 8,
textColor: .Black,
textFont: .regular(size: 16),
textAlignment: .left,
keyboardType: .default,
isSecureTextEntry: false,
autocorrectionType: .default,
spellCheckingType: .no,
autocapitalizationType: .none,
clearButtonMode: .never,
isHidden: false,
isUserInteractionEnabled: true),
text: "Text",
placeholder: "Placeholder text")
ViewHelper
let testView = ViewHelper(style: ViewStyle(backgroundColor: .Clear,
borderColor: .Clear,
borderWidth: 0,
corderRadius: 0,
clipsToBounds: true,
isHidden: false,
isUserInteractionEnabled: true))
ImageViewHelper
let testImageView = ImageViewHelper(style: ImageViewStyle(backgroundColor: .Clear,
borderColor: .Black,
borderWidth: 1,
corderRadius: 10,
contentMode: .scaleAspectFill,
clipsToBounds: true,
isHidden: false),
iconImage: "Your View Image".uiImage)
// uiImage() is a function to set image for components instead of using UIimage(named: "Image Name")
TableViewHelper
let tableView = TableViewHelper(style: TableViewStyle(backgroundColor: .Clear,
borderColor: .Clear,
borderWidth: 0,
corderRadius: 0,
clipsToBounds: true,
isHidden: false,
isUserInteractionEnabled: true),
cellClasses: [YourCell.self],
cellIdentifiers: [YourCell.reuseIdentifier])
//Using reuseIdentifier, will automically create an identifier for your cell
//Can use more than one cell, depence on what you want to display on tableview: cellClasses: [FirstCell.self,SecondCell.self], also add this code to viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerCells()
}
CollectionViewHelper
let collectionView = CollectionViewHelper(style: CollectionViewStyle(backgroundColor: .Clear,
borderColor: .Black,
borderWidth: 1,
corderRadius: 4,
clipsToBounds: true,
isHidden: false,
isUserInteractionEnabled: true),
collectionViewLayout: UICollectionViewLayout(),
cellClasses: [YourCell.self],
cellIdentifiers: [YourCell.reuseIdentifier])
//Using reuseIdentifier, will automically create an identifier for your cell
//Can use more than one cell, depence on what you want to display on collectionView: cellClasses: [FirstCell.self,SecondCell.self], also add this code to viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.registerCells()
}
PickerHelper
// DatePicker
PickerHelper.selectDate(title: "Your Picker Title",
hideCancel: false,
datePickerMode: .dateAndTime,
selectedDate: Date(),
minDate: nil,
maxDate: Date().dateByAddingYears(5),
didSelectDate: { selectedDay in
//Your Logic code with Picker
})
// Option Picker
let data = ["Option1", "Option2", "Option3", "Option4", "Option5", "Option6"]
PickerHelper.selectOption(dataArray: data) { [weak self] value, index in //value: data value, index: data order
//Your Logic code with Picker
}
授权
TSwiftHelper 在 MIT 许可下提供。更多信息请参阅LICENSE文件。