iOS 横竖屏适配 ---masonry

  

 

  要点:

    1.配置可以支持的屏幕方向(至少有横屏)

    

    2.利用约束添加控件。  一般纯代码编写UI 用masonry比较多 。 导入工程即可。简单使用masonry如下:

    

    //搜索栏
    UIImageView *searchView = [[UIImageView alloc]init];
    searchView.userInteractionEnabled = YES;
    searchView.translatesAutoresizingMaskIntoConstraints = NO;
    searchView.image = [UIImage imageNamed:@"mainVC圆角矩形"];
    [_mapView addSubview:searchView];
    [searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mapView).with.offset(40);
        make.left.equalTo(weakSelf.mapView).with.offset(20);
        make.right.equalTo(weakSelf.mapView).with.offset(-20);
        make.height.mas_equalTo(@50);
    }];

 

    //左侧菜单按钮
    UIButton *leftMenuBtn = [[UIButton alloc]init];
    [leftMenuBtn setImage:[UIImage imageNamed:@"菜单.png"] forState:UIControlStateNormal];
    [leftMenuBtn setImage:[UIImage imageNamed:@"菜单.png"] forState:UIControlStateHighlighted];
    [leftMenuBtn addTarget:self action:@selector(touchLeftMenuBtn) forControlEvents:UIControlEventTouchUpInside];
    [searchView addSubview:leftMenuBtn];
    [leftMenuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.top.equalTo(searchView).with.offset(0);
        make.left.equalTo(searchView).with.offset(0);

    }];

 

posted @ 2017-02-09 07:54  ID_超电磁炮  阅读(721)  评论(0编辑  收藏  举报