名字没想好,就暂且叫它 UIMaker
写UIMaker 动机
自 Masonry
的横空出世,其链式编程的姿势屡试不爽,相比于iOS的书写姿势更见其?, Masonry
中能实现这种链式编程方式那么iOS控件创建也一定能实现这种方式,在看完其内部实现后,在闲余时间决定自己将 UIKit 重写一遍达到其一样的效果,希望在开发过程中对开发效率和代码的可读性有一定的帮助。
UIMaker 引入
支持通过
pod UIMaker
可直接下载引入
用法示例
目前 支持创建 UILabel
、 UIButton
、 UIImageView
、 UITableView
、 UITextField
、UITextView
、UICollectionView
、AFN
后续还会继续拓展
UITextView
示例可以和 Mansony
配合使用
[[Maker(@"UITextView") mas_make:^(UIMaker * _Nonnull make) {
make.backGroudColor([UIColor orangeColor])
.parent_component(self.view)
.font([UIFont systemFontOfSize:20]);
}] mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(200);
make.left.mas_equalTo(20);
make.right.mas_equalTo(20);
make.height.mas_equalTo(50);
}];
复制代码
UILabel
示例
[Maker(@"UILabel") mas_make:^(UIMaker * _Nonnull make) {
make.text(@"UIMaker mas_make successed!")
.frame(CGRectMake(100, 100, 200, 80))
.backGroudColor([UIColor redColor])
.textColor([UIColor whiteColor])
.lineBreakMode(NSLineBreakByTruncatingMiddle)
.radian(CGSizeMake(10, 10))
.parent_component(self.view)
.font([UIFont systemFontOfSize:18])
.tapGestureRecognizer(^{
NSLog(@"UIMaker mas_make successed!");
});
}];
复制代码
AFN
示例
// get
[UIMakerrequest share].url(@"https://zhqd.shiminjia.com/weather.php").type(UIMakerrequestTypeGet).respone(^(id _Nonnull respone) {
// 成功回调
NSLog(@"respone---- %@",respone);
}, ^(id _Nonnull failure) {
// 失败回调
});
// downloadFile
[UIMakerrequest share].url(@"https://zhqd.shiminjia.com/weather.php").download(^(id _Nonnull progress) // 下载进度
// NSLog(@"progress---- %@",progress);
}, ^(id _Nonnull respone) {
// 成功回调
NSLog(@"respone---- %@",respone);
}, ^(id _Nonnull failure) {
});
// uploadFile
[UIMakerrequest share].url(@"https://zhqd.shiminjia.com/weather.php").fileData([NSData new]).fileName(@"weather.txt").name(@"file").mimeType(@"image/png").uploadFile(^(id _Nonnull progress) {
// 上传进度
}, ^(id _Nonnull respone) {
// 成功回调
}, ^(id _Nonnull failure) {
// 失败回调
});
复制代码
版本设计基线
UIMaker中几乎涵盖了日常开发过程中用到的对象,后期还会增加一些拓展,也期盼您有更好的想法为其拓展。
0.5.0 新增功能
对AFN进行拓展,在网络请求的地方也可以进行链式调用API,支持业务中常见的
post | get | put | delete
以及文件上传
和下载
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END