Swift about UIView Setting the frame value extension
Use
Description
1. Use such as, very simple, no longer repeat
2. Provide the Getter,setter method for the added calculation attribute in extension
Source
////Uiview+setrect.swift//youxianming////Created by youxianming on 15/9/29.//copyright©2015 Year youxianming All rights reserved.//Import uikitextension UIView {//xvar x:cgfloat {Get { returnframe.origin.x}Set(newval) {var tmpframe:cgrect=Frame tmpframe.origin.x=newval Frame=Tmpframe}} //yvar y:cgfloat {Get { returnFRAME.ORIGIN.Y}Set(newval) {var tmpframe:cgrect=Frame TMPFRAME.ORIGIN.Y=newval Frame=Tmpframe}} //Heightvar height:cgfloat {Get { returnFrame.size.height}Set(newval) {var tmpframe:cgrect=Frame TmpFrame.size.height=newval Frame=Tmpframe}} //widthvar width:cgfloat {Get { returnFrame.size.width}Set(newval) {var tmpframe:cgrect=Frame TmpFrame.size.width=newval Frame=Tmpframe}} // Leftvar left:cgfloat {Get { returnx}Set(newval) {x=newval}} // Rightvar right:cgfloat {Get { returnX +width}Set(newval) {x= newval-width}} //Topvar top:cgfloat {Get { returny}Set(newval) {y=newval}} //Bottomvar bottom:cgfloat {Get { returnY +Height}Set(newval) {y= newval-Height}} var centerx:cgfloat {Get { returncenter.x}Set(newval) {Center=Cgpoint (X:newval, Y:center.y)}} var centery:cgfloat {Get { returnCenter.y}Set(newval) {Center=Cgpoint (x:center.x, Y:newval)}} var middlex:cgfloat {Get { returnWidth/2}} var middley:cgfloat {Get { returnHeight/2}} var middlepoint:cgpoint {Get { returnCgpoint (X:middlex, Y:middley) }}}
Swift about UIView Setting the frame value extension