iOS 实用Category, 批量增加子视图

UIView *oneSubView = [[UIView alloc] init];
oneSubView.frame = CGRectMake(50, 50, 100, 100);

UIView *twoSubView = [[UIView alloc] init];
twoSubView.frame = CGRectMake(50, 200, 20, 20);

UIView *threeSubView = [[UIView alloc] init];
threeSubView.frame = CGRectMake(200, 200, 50, 50);

[self.view batchAddSubview:oneSubView, twoSubView, threeSubView, nil];
// or
// [self.view batchAddSubviews:@[oneSubView, twoSubView, threeSubView]];


不需要随机色调试, 可以在.m文件中, 注释掉下面该行代码即可: [(UIView *)obj setBackgroundColor:RandomColor];

GitHub: https://github.com/tomatoK/UIView-Extension

posted @ 2015-11-02 15:25  oumygade  阅读(193)  评论(0编辑  收藏  举报