在iOS 开发中适配屏的问题大家一定接触过masonry想必大家都很熟悉, masonry 简化了AutoLayout 使用方式,为开发者带来了很大的便利.本人在开发中用的一直也是Masonry,偶然机会接触到了WHC_AutoLayoutKit, 简单实用.尤其是动态布局 相比masonry更新约束更加方便了. 下面是WHC_AutoLayoutKit 实用功能
WHC_AutoLayoutKit使用方法法#####
self.picView = [[UIView alloc] init];
[self.contentView addSubview: self.picView];
[self.picView whc_LeftSpace:15]; //相对父视图的左边距
[self.picView whc_RightSpace:15];//相对父视图的右边距
[self.picView whc_TopSpace:5 relativeView:self.contentLabel];//上边相对某个子视图的距离
[self.picView whc_Height:40];//设置高度
1.隐式更新约束#####
WHC_AutoLayoutKit采用了隐式更新约束,顾名思义就是在你添加同类型约束(可能会产生冲突约束)会自动删除前面添加可能产生冲突的约束,
2.单独更新约束#####
只需要执行这一行代码即可更新self.picView高度,不需要重新约束
- (void)buttonClick{
[self.picView whc_Height:80];//点击按钮时重新更新高度
}
3.自动调整宽高#####
可根据字数自动调整高度
[self.titleLabel whc_HeightAuto];
4.cell高度计算#####
只需在tableview的heightForRowAtIndexPath方法中写入即可
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [ActionMainTableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];
}