Created
March 17, 2016 01:55
-
-
Save wuyongrui/2cb879dc0e41439671dd to your computer and use it in GitHub Desktop.
UIView+FrameAdjust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+FrameAdjust.swift | |
| // | |
| import Foundation | |
| import UIKit | |
| public extension UIView { | |
| // use left | |
| public var x:CGFloat! { | |
| get { | |
| return self.frame.origin.x | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(newValue, frame.origin.y, frame.size.width, frame.size.height) | |
| } | |
| } | |
| // use top | |
| public var y:CGFloat! { | |
| get { | |
| return self.frame.origin.y | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(frame.origin.x, newValue, frame.size.width, frame.size.height) | |
| } | |
| } | |
| public var width:CGFloat! { | |
| get { | |
| return self.frame.size.width | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(frame.origin.x, frame.origin.y, newValue, frame.size.height) | |
| } | |
| } | |
| public var height:CGFloat! { | |
| get { | |
| return self.frame.size.height | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width,newValue) | |
| } | |
| } | |
| //----------------- | |
| public var left:CGFloat { | |
| get { | |
| return self.frame.origin.x | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(newValue, frame.origin.y, frame.size.width, frame.size.height) | |
| } | |
| } | |
| public var top:CGFloat { | |
| get { | |
| return self.frame.origin.y | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(frame.origin.x, newValue, frame.size.width, frame.size.height) | |
| } | |
| } | |
| public var right:CGFloat { | |
| get { | |
| return self.frame.origin.x + self.frame.size.width | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(newValue - frame.size.width, frame.origin.y, frame.size.width, frame.size.height) | |
| } | |
| } | |
| public var bottom:CGFloat { | |
| get { | |
| return self.frame.origin.y + self.frame.size.height | |
| } | |
| set(newValue) { | |
| self.frame = CGRectMake(frame.origin.x, newValue - frame.size.height, frame.size.width, frame.size.height) | |
| } | |
| } | |
| public var centerX:CGFloat { | |
| get { | |
| return self.center.x | |
| } | |
| set(newValue) { | |
| self.center = CGPointMake(newValue, self.center.y) | |
| } | |
| } | |
| public var centerY:CGFloat { | |
| get { | |
| return self.center.y | |
| } | |
| set(newValue) { | |
| self.center = CGPointMake(self.center.x, newValue) | |
| } | |
| } | |
| public var origin:CGPoint { | |
| get { | |
| return self.frame.origin | |
| } | |
| set(newValue) { | |
| var _frame = self.frame | |
| _frame.origin = newValue | |
| self.frame = _frame | |
| } | |
| } | |
| public var size:CGSize { | |
| get { | |
| return self.frame.size | |
| } | |
| set(newValue) { | |
| var _frame = self.frame | |
| _frame.size = newValue | |
| self.frame = _frame | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment