iOS开发iOS开发资料收集区

iOS_CustomAutoLayout

2017-07-13  本文已影响108人  lesmiserables0

持续大半年的项目终于开始内侧了,空闲之余, 总结一下,这次用到的一些可重用代码,都是一些轻量级的原生类的分类,封装等,代码不是我原创的,有借鉴,也有改动。
UIView+CustomAutoLayout
这个Category,简单易懂,功能强大。代码地址在这里:https://github.com/lesmiserables0/iOS_CustomAutoLayout
使用方法:

UIView *backView = [[UIView alloc]init];
backView.backgroundColor = kWhiteColor;
[self addSubview:backView]; 

UILabel *label = [[UILabel alloc]init];
label.text = @"这是个标签";
label.font = [UIFont systemFontOfSize:34*Parameter];
label.textColor = kBlackColor;
[self addSubview:label];

[label sizeToFit];
[label alignTop:backView margin:-45*Parameter];
[label alignLeft:backView margin:42*Parameter];

 UIImageView *groupIcon = [[UIImageView alloc]init];
[groupIcon sd_setImageWithURL:[NSURL URLWithString:_groupIconUrl] placeholderImage:kDefaultGroupIcon];
[self addSubview:groupIcon];

[groupIcon sizeWith:CGSizeMake(80*Parameter, 80*Parameter)];
[groupIcon layoutBelow:label margin:24*Parameter];
[groupIcon alignLeft:backView margin:40*Parameter];

以上方法只是简单的从上往下布局,还有其他复杂布局方法,网格式布局等。代码注释很详细。有需要的可以去阅读源码,顺便加个星。

上一篇下一篇

猜你喜欢

热点阅读