SRView
入门
使用Swift以代码方式编写UI有时可能会很烦恼,因为您必须定义所有这些UI可变变量,它们在内部返回另一个UI类,这在很大程度上是非常混乱和令人烦恼的。使用SRView,事情要简单得多:只需定义一个sr类型的视图并添加您的选项即可
安装
CocoaPods
使用pod 'SRView'
或者从Sources文件夹复制Swift文件
如何使用
首先导入SKView
import SRView
之后
let view = sr.view([.backgroundColor(.red), .cornerRadius(5.0)]) // UIView
无需将translatesAutoresizingMaskIntoConstraints
设置为false
当前支持的UIView
let view = sr.view() // UIView
let image = sr.image() // UIImageView
let label = sr.label() // UILabel
let button = sr.button() // UIButton
let textField = sr.textField() // UITextField
let textView = sr.textView() // UITextView
let slider = sr.slider() // UISlider
let Switch = sr.Switch() // UISwitch
let table = sr.table() // UITableView
let collection = sr.collection() // UICollectionView
之后将添加更多
SRView选项
必须以选项数组的形式添加
let textLabel = sr.label([.text("Hello World!"), .textColor(.red), .textAlignment(.center)])
// OR
let options : [SRVOptions] = [.text("click me!"), .backgroundColor(.blue), .alpha(0.7)]
let testButton = sr.button(options)
case alpha(CGFloat)
case numberOfLines(Int)
case backgroundColor(UIColor)
case tintColor(UIColor)
case textColor(UIColor)
case clipsToBounds(Bool)
case cornerRadius(CGFloat)
.
.
.
etc
完整列表请点击此处
待办事项
- 添加更多UIView,如webView,segmentedView等
- 添加更多选项
- 让sr工作为一个扩展
- 更多徽章
许可协议
制作于
MIT License
Copyright (c) 2018 Zaid Amer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.