如何使用Masonry第三方库,来约束纯代码中的控件
来源:互联网 发布:优惠券采集源码 编辑:程序博客网 时间:2024/06/05 00:32
大概学习IOS课程快4个月了,然后最近才开始接触第三方库。就自己来整理下Masonry的使用
这是下载好的Masonry 里面的文件,我们暂时只用到其中的Masonry。
在项目中选择Add Files to xxxx 来导入Masonry 这个库,然后在ViewController中包含一下
#import "ViewController.h"#import "Masonry.h"
因为是纯代码 ,所以要把根视图加载到Window 上 具体代码如下
在AppDelegate.h 中声明
@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) ViewController *rootView;
在.m中是
@implementation AppDelegate@synthesize rootView;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]]; self.window.backgroundColor = [UIColor whiteColor]; self.rootView = [[ViewController alloc]init]; [self.window setRootViewController:self.rootView]; [self.window makeKeyAndVisible]; return YES;}
然后是一个小demo 练习,应用Masonry对控件的约束
//添加一个背景图片 self.bgView =[[UIImageView alloc]init]; self.bgView.image =[UIImage imageNamed:@"loginbg.png"]; [self.view addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { //通过top和left 确认self.bgView 的左上角原点 make.top.equalTo(self.view.mas_top); make.left.equalTo(self.view.mas_left); //通过CGSizeMake 确认self.bgView 的长宽数据 make.size.mas_equalTo(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)); }];
再加一个按钮和一个LOGO 图片
//关闭按钮 self.backBtn = [[UIButton alloc]init]; [self.backBtn setBackgroundImage:[UIImage imageNamed:@"closebt.png"] forState:UIControlStateNormal]; // [self.backBtn addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.backBtn]; [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view.mas_top).with.offset(30); make.left.equalTo(self.view.mas_left).with.offset(10); make.size.mas_equalTo(CGSizeMake(21, 21)); }]; //logo 图片 self.logolmg = [[UIImageView alloc]init]; self.logolmg.image = [UIImage imageNamed:@"LOGO.png"]; [self.view addSubview:self.logolmg]; [self.logolmg mas_makeConstraints:^(MASConstraintMaker *make) { //通过top和centerx确认self.logolmg的中心点 make.top.equalTo(self.view.mas_top).with.offset(105); make.centerX.mas_equalTo(self.view.mas_centerX); make.size.mas_equalTo(CGSizeMake(104, 104)); }];
还有的就不都展示了 最后的效果是
0 0
- 如何使用Masonry第三方库,来约束纯代码中的控件
- 纯代码实现 AutoLayout 使用第三方框架 Masonry
- 第三方 Masonry约束的使用
- IOS纯代码布局的第三方框架masonry
- iOS开发- Masonry约束第三方详解
- iOS学习之Masonry第三方约束
- swift下面使用第三方Masonry 的代码
- iOS 第三方库 - Masonry
- ios Autolayout 第三方库Masonry 使用介绍文章链接
- iOS自动布局第三方库Masonry的使用
- 第三方库Masonry自动布局AutoLayout使用
- delphi中的第三方控件如何安装
- delphi中的第三方控件如何安装
- 关于用第三方Masonry约束适配
- 第三方控件Masonry和IOS代码实现Autolayout的比较
- 纯代码添加masonry约束注意点记录一
- 第三方框架Masonry的基本使用
- 自动适配 使用masonry 第三方
- javaSE学习笔记之面向对象程序设计(二)
- 【牛腩】真假分页
- 好记性不如烂笔头——关于精确度、召回率、F值、准确率
- 协议设计中ACK机制的影响
- 字体和常用web字体
- 如何使用Masonry第三方库,来约束纯代码中的控件
- 《java课程设计》之猜猜看游戏(四)
- Java EE发展史
- Linux下获取块设备大小
- String Transmission
- 【C++】通用单链表
- JDK、JRE和JVM三者之间的关系
- Python2.x_流程控制
- How to Copy and Paste in the Ubuntu Gnome Terminal