VFL演示样例

VFL演示样例

上篇文章向大家介绍了VFL的基本的语法点,假设对下面演示样例不熟的童鞋,能够前去參考。废话不多说。我们直接来看演示样例。

演示样例一

将五个大小同样、颜色不同的view排成一行,view间的间隔为15px,第一个view的间隔与屏幕的左边间隔10px,最后一个view的间隔与屏幕的右边间隔也为10px

//依据屏幕的宽度。计算view的宽度和高度CGFloat width = ([[UIScreen mainScreen] bounds].size.width-2*10-4*15)/5;CGFloat height = width;//固定第一个viewUIView *firstView = [UIView new];firstView.backgroundColor = [UIColor blackColor];// 将次属性设置为NO,表示将使用AutoLayout的方式来布局firstView.translatesAutoresizingMaskIntoConstraints = NO;[self.view addSubview:firstView];//------使用VFL为第一个view加入约束------//在水平方向上,让firstview的左边与父视图的左边间隔10px,且自身宽度为widthNSArray *constraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[firstView(==width)]" options:0 metrics:@{@"width":@(width)} views:NSDictionaryOfVariableBindings(firstView)];//在垂直方向上,让firstView的上边与父视图的上边间隔100px,且自身的高度为heightNSArray *constraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[firstView(==height)]" options:0 metrics:@{@"height":@(height)} views:NSDictionaryOfVariableBindings(firstView)];[self.view addConstraints:constraints1];[self.view addConstraints:constraints2];//定义一个颜色数组NSArray *colors = @[[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor blueColor]];//定义一个views数组NSMutableArray *views = [NSMutableArray array];[views addObject:firstView];for (int i = 0; i < 4; i++) {UIView *view = [UIView new];view.backgroundColor = colors[i];view.translatesAutoresizingMaskIntoConstraints = NO;[self.view addSubview:view];[views addObject:view];}//依次给views数组中的view使用vfl加入约束for (int i = 1; i < views.count; i++) {UIView *view1 = views[i-1];UIView *view2 = views[i];NSDictionary *bindings = NSDictionaryOfVariableBindings(view1,view2);NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[view1]-15-[view2(==width)]" options:0 metrics:@{@"width":[NSNumber numberWithFloat:width]} views:bindings];[self.view addConstraints:constraints];}UIView *view1 = views[0];for (int i = 0; i < views.count; i++) {UIView *view2 = views[i];NSDictionary *bindings = NSDictionaryOfVariableBindings(view1,view2);NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[view2(==view1)]" options:0 metrics:nil views:bindings];[self.view addConstraints:constraints];}

效果截图:
效果截图


下篇演示样例将会是使用VFL对登录界面进行布局,喜欢我的博客的童鞋能够关注一波!

posted on 2017-07-07 15:51 mthoutai 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/mthoutai/p/7132606.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/252367.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

evo实用指令指南

下面这篇文章中有比较具体的关于evo的安装以及使用的介绍&#xff0c;其中一点很重要&#xff0c;就是可以把euroc形式的.csv的轨迹格式转换为tum格式的轨迹。 https://zhuanlan.zhihu.com/p/88223106#single evo_traj tum orb_slam2_tum.txt --reftum_groundtruth.txt -p --pl…

MailUtils

/***包名:com.thinkgem.jeesite.test*描述:package com.thinkgem.jeesite.test;*/ package com.thinkgem.jeesite.test;import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.u…

ES6遍历对象

遍历对象 E S 6 一共有 5 种方法可以遍历对象的属性 。 for ... in for . . . in 循环遍历对象自身的和继承的可枚举属性&#xff08;不含 Symbol 属性&#xff09;。 Object.keys(obj)Object . keys 返回 一个数组&#xff0c;包括对象自身的&#xff08;不含继承的 &#xff…

SpringMvc中ModelAndView模型的应用

/** * 目标方法的返回值可以是 ModelAndView 类型。 * 其中可以包含视图和模型信息 * SpringMVC 会把 ModelAndView 的 model 中数据放入到 request 域对象中. * return */ RequestMapping("/testModelAndView") public ModelAndView testModelAndView(){ String v…

ubuntu16.04 + ros-kinetic 配置cartographer

其实一直以来都感觉纯视觉SLAM很难落地产品&#xff0c;所以一直在找机会学习激光slam,之前也在深蓝学院上买了一个激光salm的课程&#xff0c;惭愧&#xff0c;至今也没开始学呢&#xff0c;年底之前&#xff0c;我想工作之余研究一下激光slam和ros&#xff0c;我感觉这两个东…

virtualbox中安装ubuntu

为什么80%的码农都做不了架构师&#xff1f;>>> virtualboxubuntu 安装virtualbox&#xff0c;当前版本是6.0.4下载ubuntu安装盘&#xff0c;建议lubuntu&#xff0c;链接是http://mirrors.ustc.edu.cn/ubuntu-cdimage/lubuntu/releases/18.04.2/release/lubuntu-1…

面向对象重写(override)与重载(overload)区别

一、重写&#xff08;override&#xff09; override是重写&#xff08;覆盖&#xff09;了一个方法&#xff0c;以实现不同的功能。一般是用于子类在继承父类时&#xff0c;重写&#xff08;重新实现&#xff09;父类中的方法。 重写&#xff08;覆盖&#xff09;的规则&#…

cartographer学习笔记--如何保存cartagrapher_ros建好的地图

今天开始跟着网友大佬学习cartographer. 1. 如何保存cartographer的地图数据 在运行cartographer过程中可以随时保存建好的地图&#xff0c;步骤如下&#xff1a; 首先是重新打开一个terminal, 如果你没有将你的cartographer_ros下的setup.bash文件写入到.bashrc中&#xff…

Java微信公众号开发(五)—— SVN版本控制工具

1 作用 两个疑问&#xff1a; 什么是版本控制&#xff1f;为什么要用版本控制工具&#xff1f;作用&#xff1a; 受保护受约束合作开发中&#xff0c;版本控制工具更重要的作用就是让开发者更好地协作&#xff0c;每个人的代码既能互相调用&#xff0c;来共同完成一个较大的功…

Linux之《荒岛余生》(二)CPU篇

为什么80%的码农都做不了架构师&#xff1f;>>> 温馨提示&#xff0c;动图已压缩&#xff0c;流量党放心查看。CPU方面内容不多&#xff0c;我们顺便学点命令。本篇是《荒岛余生》系列第二篇&#xff0c;垂直观测CPU。其余参见&#xff1a; Linux之《荒岛余生》&am…

PTA 06-图2 Saving James Bond - Easy Version (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/672 5-10 Saving James Bond - Easy Version (25分) This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the worlds most famous spy, was captured by…

Ubuntu16.04上安装kitti2bag

kitti2bag是一个可以将kitti数据集转换为bag文件的工具&#xff0c;可以直接通过pip进行安装。由于kitti2bag中使用到ros&#xff0c;所以安装时你使用的python版本应该是2.7的因为ros只有在Python2.7时才能正常工作。比如说我&#xff0c;我安装了conda&#xff0c;在conda中安…

Nginx之windows下搭建

去nginx.org下载nginx 以nginx-1.8.1为例解压到D盘nginx-1.8.1目录 假设NGINX_HOME为D:\nginx-1.8.1 3种启动途径&#xff1a; 一、双击nginx.exe图标&#xff0c;可见黑窗口一闪而过&#xff0c;启动完毕。 二、命令行到nginx目录&#xff0c;输入nginx启动。&#xff08;注&a…

单片机错误笔记

记录下使用单片机过程中的一些错误&#xff0c;便于以后查询&#xff1a; 单片机型号&#xff1a;STC15F2K60S2 晶振&#xff1a;18.432 报错代码&#xff1a; *** WARNING L1: UNRESOLVED EXTERNAL SYMBOLSYMBOL: REC_DAT1MODULE: .\Objects\usart.obj (USART) …

软件开发记录03

今天我完成了软件设置&#xff0c;预算列表&#xff0c;添加预算的页面布局。 &#xff08;1&#xff09;软件设置 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"…

395. Longest Substring with At Least K Repeating Characters

题目要求 Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input: s "aaabb", k 3Output: 3The longest substring is "aaa&qu…

UICollectionView 具体解说学习

UICollectionView 和UITableView非常像,是APPLE公司在iOS 6后推出的用于处理图片这类UITableView 布局困难的控件,和UITableView 一样,它也有自己的Datasource和delegate。以下具体说下像这种方式的效果. 首先来看看UICollectionView 的DataSource。protocol UICollectionView…

70.文件异常

ferror检测文件异常perror提示文件错误信息clearerr清除异常,让文件指针回到开头完整代码 1 #define _CRT_SECURE_NO_WARNINGS2 #include<stdio.h>3 #include<stdlib.h>4 //perror提示文件错误信息5 //ferror检测文件异常6 //clearerr清除异常,让文件指针回到开头…

ServiceNow 中关于UI Action 在portal端的使用

在 portal端是可以使用Form和UI Action的&#xff0c;例如&#xff1a;var data.f $sp.getForm()&#xff1b;//需要添加上相应参数在开箱组件Form的Server script中就有如下代码&#xff1a;data.f $sp.getForm(data.table, data.sys_id, data.query, data.view);data.f对象中…

特殊密码锁

总时间限制: 1000ms内存限制: 1024kB描述有一种特殊的二进制密码锁&#xff0c;由n个相连的按钮组成&#xff08;n<30&#xff09;&#xff0c;按钮有凹/凸两种状态&#xff0c;用手按按钮会改变其状态。 然而让人头疼的是&#xff0c;当你按一个按钮时&#xff0c;跟它相邻…