LJTool
LJTool簡介
在開發過程中,有一些常用擴展每次都會用到,每次拷貝來拷貝去,有點煩了,就封裝成了一個工具庫,使用pod來管理,方便多了。LJTool主要分成三大塊:
1. 配色類,封裝了一些常用的顏色。
2. 控件初始化,把控件的創建和常用的屬性設置封裝了一下,并且加了一些占位符
3. 其它,包括圖片的創建和button的內容排列方式
安裝
在Podfile
加入
pod 'LJTool'
然后執行下面命令即可
pod install
基本使用
1. UIColor 類
根據RGB創建UIColor
UIColor.lj.color(r: 10, g: 10, b: 10)
根據16進制創建UIColor
UIColor.lj.color(0x123456, alpha: 1)
一些常用顏色的用法,查看LJColorViewController
文件
lJTool
2. UI Create
可看demo中LJTool_UICreateViewController
中的用法,創建完后默認會有占位符。
LJTool
- UITableView
fileprivate lazy var tableView: UITableView = {
let tableView: UITableView = UITableView.lj.tableView(dataSource: self, delegate: self)
tableView.backgroundColor = UIColor.lj.background
tableView.register(LJTableViewCell.self, forCellReuseIdentifier: kLJTableViewCell)
return tableView
}()
- CollectionView
fileprivate lazy var imageCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collection = UICollectionView.lj.collectionView(layout: layout, dataSource: self, delegate: self)
collection.register(LJCollectionViewCell.self, forCellWithReuseIdentifier: kLJCollectionViewCell)
return collection
}()
- UILabel,推薦使用fontStyle方法,詳情請查看Building Apps with Dynamic Type
fileprivate lazy var userNameLabel: UILabel = {
let label = UILabel.lj.label(textColor: UIColor.lj.text, fontStyle: UIFontTextStyle.headline)
return label
}()
- UIImage
fileprivate lazy var logoImageView: UIImageView = {
let imageView = UIImageView.lj.imageView()
return imageView
}()
- UIButton
fileprivate lazy var commentButton: UIButton = {
let button = UIButton.lj.button(title: "20", titleColor: UIColor.lj.gray999, fontSize: 14, image: #imageLiteral(resourceName: "icon_評論"))
return button
}()
- UITextField
fileprivate lazy var textField: UITextField = {
let textField: UITextField = UITextField.lj_textField(placeholder: "placeholder", leftView: nil, rightView: nil)
return textField
}()
- 創建圖片
創建圖片主要有兩個方法,一個是根據顏色值創建圖片,一個是創建二維碼圖片
let QRImage = UIImage.lj.QRImage("test")
let colorImage = UIImage.lj.image(with: UIColor.red)
- UIButton 內容排列
commentButton.lj.alignImageRightTitleLeft()
collectionButton.lj.alignImageUpTitleDown()
enter image description here
- 正則匹配
string.lj.matchingRegExp("^\\+?(?:[1-9]\\d*(?:\\.\\d{1,2})?|0\\.(?:\\d[1-9]|[1-9]\\d))$")
聯系我
有好的建議或者反饋可發Issues