IOS Masonry自动布局

2024-02-28 15:18
文章标签 布局 自动 ios masonry

本文主要是介绍IOS Masonry自动布局,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前项目用Frame布局,这个项目登录用了VFL,后来觉得用Masonry,前天布局TableViewCell时用了下 ,觉得还不错。

#import "Masonry.h"
#import "MASViewAttribute.h"

先看效果图:

#import "ReportsCell.h"
//#import "Masonry.h"
#import "YZPUIFormatMacros.h"
#import "Global.h"static const CGFloat kIconWidth                 = 55.0f;
static const CGFloat kIconHeight                = 55.0f;@implementation ReportsCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];if (self) {self.backgroundColor = [UIColor whiteColor];UIView *headerView = [[UIView alloc]init];headerView.backgroundColor = YZPColorDividingLineOutdide;[self addSubview:headerView];[headerView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(@0);make.top.equalTo(@0);make.width.equalTo(@(MainWidth));make.height.equalTo(@(YZPSpaceHSmall));}];UIView *topLine=[self lineView];[headerView addSubview:topLine];[topLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.top);make.left.equalTo(headerView.left);make.width.equalTo(headerView.width);make.height.equalTo(@0.5);}];UIView *bottomLine=[self lineView];[headerView addSubview:bottomLine];[bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.bottom).with.offset(-0.5);make.left.equalTo(headerView.left);make.width.equalTo(headerView.width);make.height.equalTo(@0.5);}];_orderIdLabel=[[UILabel alloc]init];_orderIdLabel.font = YZPFontSubhead;_orderIdLabel.textColor = YZPColorTextSubhead;[self addSubview:_orderIdLabel];[_orderIdLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(headerView.bottom).with.offset(15);make.left.equalTo(@10);make.width.equalTo(headerView.width);make.height.equalTo(@20);}];_orderIconView=[[UIImageView alloc]init];[self addSubview:_orderIconView];[_orderIconView makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(@15);make.top.equalTo(_orderIdLabel.bottom).with.offset(15);make.width.equalTo(@(kIconWidth));make.height.equalTo(@(kIconHeight));}];_orderTitleLabel=[[UILabel alloc]init];_orderTitleLabel.font=YZPFontSubhead;_orderTitleLabel.textColor=[UIColor colorWithRed:0.141f green:0.141f blue:0.141f alpha:1.00f];_orderTitleLabel.numberOfLines=2;[self addSubview:_orderTitleLabel];[_orderTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_orderIconView.right).with.offset(15);make.top.equalTo(_orderIconView.top).with.offset(2);make.width.equalTo(@(MainWidth-170));make.height.lessThanOrEqualTo(@(35));}];_orderSpecLabel=[[UILabel alloc]init];_orderSpecLabel.font=YZPFontExplain;_orderSpecLabel.textColor=[UIColor colorWithRed:0.400f green:0.400f blue:0.400f alpha:1.00f];[self addSubview:_orderSpecLabel];[_orderSpecLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_orderTitleLabel.left);make.top.equalTo(_orderTitleLabel.bottom).offset(10);make.width.equalTo(@(MainWidth-135));make.height.lessThanOrEqualTo(@(20));}];_productsCountLabel=[[UILabel alloc]init];_productsCountLabel.font=YZPFontContent;_productsCountLabel.textAlignment=NSTextAlignmentRight;_productsCountLabel.textColor=[UIColor colorWithRed:0.400f green:0.400f blue:0.400f alpha:1.00f];[self addSubview:_productsCountLabel];[_productsCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_orderTitleLabel.top);make.left.equalTo(_orderTitleLabel.right).offset(5);make.right.equalTo(self.right).with.offset(-15);make.height.equalTo(_orderTitleLabel.height);}];UIView *centerLine=[self lineView];[self addSubview:centerLine];[centerLine mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_orderIconView.bottom).offset(15);make.left.equalTo(self);make.width.equalTo(self);make.height.equalTo(@0.5);}];_userNameLabel=[[UILabel alloc]init];_userNameLabel.font=YZPFontExplain;_userNameLabel.textColor=YZPColorTextExplain;
//        _userNameLabel.numberOfLines=2;_userNameLabel.textAlignment=NSTextAlignmentLeft;[self addSubview:_userNameLabel];[_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.left).with.offset(15);make.top.equalTo(centerLine.bottom).offset(10);make.width.lessThanOrEqualTo(@150);make.height.lessThanOrEqualTo(@35);}];_userPhoneLabel=[[UILabel alloc]init];_userPhoneLabel.font=YZPFontExplain;_userPhoneLabel.textColor=YZPColorTextExplain;_userPhoneLabel.textAlignment=NSTextAlignmentRight;[self addSubview:_userPhoneLabel];[_userPhoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_userNameLabel.top);make.right.equalTo(self.right).with.offset(-15);make.height.lessThanOrEqualTo(@35);make.width.lessThanOrEqualTo(@150);}];_userAddressLabel=[[UILabel alloc]init];_userAddressLabel.font=YZPFontExplain;_userAddressLabel.textColor=YZPColorTextExplain;[self addSubview:_userAddressLabel];[_userAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_userNameLabel.bottom).with.offset(10);make.left.equalTo(self.left).with.offset(15);
//            make.bottom.equalTo(self.bottom).with.offset(-10);make.width.equalTo(self.width);make.height.lessThanOrEqualTo(@35);}];}return self;
}
-(UIView *)lineView
{UIView *line=[[UIView alloc]init];
//    line.backgroundColor=[UIColor redColor];line.backgroundColor=[UIColor colorWithRed:0.800f green:0.800f blue:0.800f alpha:1.00f];return line;
}- (void)awakeFromNib {// Initialization code
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state
}@end


这篇关于IOS Masonry自动布局的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/755868

相关文章

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

Python3 BeautifulSoup爬虫 POJ自动提交

POJ 提交代码采用Base64加密方式 import http.cookiejarimport loggingimport urllib.parseimport urllib.requestimport base64from bs4 import BeautifulSoupfrom submitcode import SubmitCodeclass SubmitPoj():de

【iOS】MVC模式

MVC模式 MVC模式MVC模式demo MVC模式 MVC模式全称为model(模型)view(视图)controller(控制器),他分为三个不同的层分别负责不同的职责。 View:该层用于存放视图,该层中我们可以对页面及控件进行布局。Model:模型一般都拥有很好的可复用性,在该层中,我们可以统一管理一些数据。Controlller:该层充当一个CPU的功能,即该应用程序

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器

Apache Tiles 布局管理器

陈科肇 =========== 1.简介 一个免费的开源模板框架现代Java应用程序。  基于该复合图案它是建立以简化的用户界面的开发。 对于复杂的网站,它仍然最简单,最优雅的方式来一起工作的任何MVC技术。 Tiles允许作者定义页面片段可被组装成在运行一个完整的网页。  这些片段,或Tiles,可以用于为了降低公共页面元素的重复,简单地包括或嵌入在其它瓦片,制定了一系列可重复使用

【CSS in Depth 2 精译_023】第四章概述 + 4.1 Flexbox 布局的基本原理

当前内容所在位置(可进入专栏查看其他译好的章节内容) 第一章 层叠、优先级与继承(已完结) 1.1 层叠1.2 继承1.3 特殊值1.4 简写属性1.5 CSS 渐进式增强技术1.6 本章小结 第二章 相对单位(已完结) 2.1 相对单位的威力2.2 em 与 rem2.3 告别像素思维2.4 视口的相对单位2.5 无单位的数值与行高2.6 自定义属性2.7 本章小结 第三章 文档流与盒模型(已

Shell脚本实现自动登录服务器

1.登录脚本 login_server.sh #!/bin/bash# ReferenceLink:https://yq.aliyun.com/articles/516347#show all host infos of serverList.txtif [[ -f ./serverList.txt ]]thenhostNum=`cat ./serverList.txt | wc -l`e

Jenkins 通过 Version Number Plugin 自动生成和管理构建的版本号

步骤 1:安装 Version Number Plugin 登录 Jenkins 的管理界面。进入 “Manage Jenkins” -> “Manage Plugins”。在 “Available” 选项卡中搜索 “Version Number Plugin”。选中并安装插件,完成后可能需要重启 Jenkins。 步骤 2:配置版本号生成 打开项目配置页面。在下方找到 “Build Env