ios 第三方库 html,ios - masonry第三方库使用自动布局(参考:http://www.cocoachina.com/ios/20141219/10702.html)...

#import "ViewController.h"

#import "Masonry.h"

#define kWeakSelf(weakSelf) __weak typeof(self)weakSelf = self

#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;

@interfaceViewController ()

{

UIView*topView;

}@end

@implementationViewController- (void)viewDidLoad {

[super viewDidLoad];

kWeakSelf(ws);/**底部灰色view*/topView=[[UIView alloc]init];

topView.backgroundColor=[UIColor lightGrayColor];

[ws.view addSubview:topView];

[topView mas_makeConstraints:^(MASConstraintMaker *make) {

make.center.equalTo(ws.view);

make.size.mas_equalTo(CGSizeMake(300, 300));

}];/**表面红色view*/UIView*redView=[[UIView alloc]init];

redView.backgroundColor=[UIColor redColor];

[topView addSubview:redView];

[redView mas_makeConstraints:^(MASConstraintMaker *make) {

make.edges.equalTo(topView).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));

}];/**

创建三个等宽等高等间距view*/

/**左边view*/UIView*leftView =[[UIView alloc]init];

leftView.backgroundColor=[UIColor blueColor];

[redView addSubview:leftView];/**右边view*/UIView*rightView =[[UIView alloc]init];

rightView.backgroundColor=[UIColor brownColor];

[redView addSubview:rightView];/**最有边view*/UIView*lastView =[[UIView alloc]init];

lastView.backgroundColor=[UIColor yellowColor];

[redView addSubview:lastView];

CGFloat padding= 10.f;//左边view添加约束

[leftView mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerY.mas_equalTo(redView.mas_centerY);

make.left.equalTo(redView.mas_left).with.offset(padding);

make.right.equalTo(rightView.mas_left).with.offset(-padding);

make.height.mas_equalTo(@150);

make.width.equalTo(rightView);

}];//右边view添加约束

[rightView mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerY.mas_equalTo(redView.mas_centerY);

make.left.equalTo(leftView.mas_right).with.offset(padding);

make.right.equalTo(lastView.mas_left).with.offset(-padding);

make.height.mas_equalTo(@150);

make.width.equalTo(lastView);

}];//最右边view添加约束

[lastView mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerY.mas_equalTo(redView.mas_centerY);

make.left.equalTo(rightView.mas_right).with.offset(padding);

make.right.equalTo(redView.mas_right).with.offset(-padding);

make.width.equalTo(rightView);

make.height.mas_equalTo(@150);

}];

}- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

}@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值