swift关于UIView设置frame值的extension

使用

说明

1. 使用如上图,很简单,不再赘述

2. 在extension给添加的计算属性提供getter,setter方法即可

源码

//
// UIView+SetRect.swift
// YouXianMing
//
// Created by YouXianMing on 15/9/29.
// Copyright © 2015年 YouXianMing All rights reserved.
// import UIKit extension UIView { // x
var x : CGFloat { get { return frame.origin.x
} set(newVal) { var tmpFrame : CGRect = frame
tmpFrame.origin.x = newVal
frame = tmpFrame
}
} // y
var y : CGFloat { get { return frame.origin.y
} set(newVal) { var tmpFrame : CGRect = frame
tmpFrame.origin.y = newVal
frame = tmpFrame
}
} // height
var height : CGFloat { get { return frame.size.height
} set(newVal) { var tmpFrame : CGRect = frame
tmpFrame.size.height = newVal
frame = tmpFrame
}
} // width
var width : CGFloat { get { return frame.size.width
} set(newVal) { var tmpFrame : CGRect = frame
tmpFrame.size.width = newVal
frame = tmpFrame
}
} // left
var left : CGFloat { get { return x
} set(newVal) { x = newVal
}
} // right
var right : CGFloat { get { return x + width
} set(newVal) { x = newVal - width
}
} // top
var top : CGFloat { get { return y
} set(newVal) { y = newVal
}
} // bottom
var bottom : CGFloat { get { return y + height
} set(newVal) { y = newVal - height
}
} var centerX : CGFloat { get { return center.x
} set(newVal) { center = CGPoint(x: newVal, y: center.y)
}
} var centerY : CGFloat { get { return center.y
} set(newVal) { center = CGPoint(x: center.x, y: newVal)
}
} var middleX : CGFloat { get { return width /
}
} var middleY : CGFloat { get { return height /
}
} var middlePoint : CGPoint { get { return CGPoint(x: middleX, y: middleY)
}
}
}

swift关于UIView设置frame值的extension的更多相关文章

  1. swift为UIView添加extension扩展frame

    添加swift file:UIView+Extension import UIKit extension UIView { // x var x : CGFloat { get { return fr ...

  2. Swift语言中为外部参数设置默认值可变参数常量参数变量参数输入输出参数

    Swift语言中为外部参数设置默认值可变参数常量参数变量参数输入输出参数 7.4.4  为外部参数设置默认值 开发者也可以对外部参数设置默认值.这时,调用的时候,也可以省略参数传递本文选自Swift1 ...

  3. swift - UIView 设置背景色和背景图片

    代码如下: let page = UIView() page.frame = self.view.bounds //直接设置颜色 page.backgroundColor = UIColor.gree ...

  4. UIView 中 frame, bounds, center 属性的关系

    最近一直在学 iOS 开发,所以专门创建了这样一个类别,将自己学习中的一些问题整理,记录下来.由于自己是初学者,所以所写的文章非常基础,写这个类别一是为了给自己留下存 档,二是为了给和我有同样问题的初 ...

  5. 便利的初始化view以及设置tag值

    便利的初始化view以及设置tag值 效果 源码 https://github.com/YouXianMing/iOS-Project-Examples 中的 SetRect // // Access ...

  6. CALayer的position,anchorPoint属性 与UIView的frame 属性

    彻底理解CALayer的position,anchorPoint属性 与UIView的frame 属性 一.position,anchorPoint两者都是CALayer的属性,都是CGPoint点 ...

  7. iOS UIView设置圆角

    UIView设置圆角 1.比较简单的情况,UIView四个角都是圆角: UIView *aView = [[UIView alloc] init]; aView.frame = CGRectMake( ...

  8. UIView的frame和bounds区别

    UIView的frame和bounds区别 iOS中,大家肯定对view和frame都不陌生,我们设置view在父view中的位置和大小时,只需要设置frame就可以了. 可能大家也有查过网上的一些资 ...

  9. [UIKit学习]01.关于UIView,frame,bounds,center

    UIView是Cocoa大多控件的父类,本身不带事件. UIView的常见用法 @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 ...

随机推荐

  1. PostgreSQL执行超时的问题

    PostgreSQL执行超时的问题 使用背景 最近在使用PostgreSQL的时候,在执行一些数据库事务的时候,先后出现了statement timetout 和idle-in-transaction ...

  2. dynamic解析Http xml格式响应数据

    继续上一篇 构建RESTful风格的WCF服务 ,咱已经把服务端的数据和服务准备好了,客户端调用 wcf rest接口后如何解析xml?下面使用dynamic关键字解析来至于WCF REST XML响 ...

  3. 面试题26:合并k个排好序的单链表

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. c ...

  4. VF

    VF 描述 Vasya is the beginning mathematician. He decided to make an important contribution to the scie ...

  5. SQL运算符

    SQL运算符实例代码教程 - 运算符是一个保留字或字符,主要用于在SQL语句的WHERE子句来执行,比较和算术运算等操作.  http://www.yiibai.com/sql/sql_operato ...

  6. catch异常

    int ret = -1; try { ret = tBuyerCodeApplyInfoService.insertTBuyerCodeApplyInfoBySelective(buyerCode) ...

  7. Walkway.js – 创建简约的 SVG 线条动画

    Walkway.js 是一个使用线条和路径元素组成 SVG 动画图像的简单方法.只需根据提供的配置对象创建一个新的 Walkway 实例就可以了.这种效果特别适合那些崇尚简约设计风格的网页.目前, W ...

  8. C#动态创建Gridview及批量插入到数据库

    这里介绍两种动态创建Gridview的方法: (一).有时需要应付上头领导的检查,所以就弄一些静态的Gridview来显示数据,这种方法的优点就是不用连接数据库,比较方便,但是代码灵活性不高,所有数据 ...

  9. 从api接口获取数据-okhttp

    首先先介绍下api接口: API:应用程序接口(API:Application Program Interface) 通常用于数据连接,调用函数提供功能等等... 从api接口获取数据有四种方式:Ht ...

  10. fzu 2155 盟国

    Problem 2155 盟国 Accept: 39    Submit: 129Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem De ...