Created
September 17, 2022 20:40
-
-
Save calimarkus/d00ea88d18cca6b2572e765f68b9d180 to your computer and use it in GitHub Desktop.
UIView+Positioning.swift
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+Positioning.swift | |
// | |
import UIKit | |
extension UIView { | |
var frameOrigin: CGPoint { | |
get { frame.origin } | |
set(origin) { frame = CGRectMake(origin.x, origin.y, frame.size.width, frame.size.height) } | |
} | |
var frameSize: CGSize { | |
get { frame.size } | |
set(newSize) { frame = CGRectMake(frame.origin.x, frame.origin.y, newSize.width, newSize.height) } | |
} | |
var frameX: CGFloat { | |
get { frame.origin.x } | |
set(newX) { frame = CGRectMake(newX, frame.origin.y, frame.size.width, frame.size.height) } | |
} | |
var frameY: CGFloat { | |
get { frame.origin.y } | |
set(newY) { frame = CGRectMake(frame.origin.x, newY, frame.size.width, frame.size.height) } | |
} | |
var frameWidth: CGFloat { | |
get { frame.size.width } | |
set(newWidth) { frame = CGRectMake(frame.origin.x, frame.origin.y, newWidth, frame.size.height) } | |
} | |
var frameHeight: CGFloat { | |
get { frame.size.height } | |
set(newHeight) { frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, newHeight) } | |
} | |
var centerX: CGFloat { | |
get { center.x } | |
set(centerX) { center = CGPointMake(centerX, center.y) } | |
} | |
var centerY: CGFloat { | |
get { center.y } | |
set(centerY) { center = CGPointMake(center.x, centerY) } | |
} | |
var frameRight: CGFloat { | |
get { frame.origin.x + frame.size.width } | |
set(newRight) { frame = CGRectMake(newRight - frame.size.width, frame.origin.y, frame.size.width, frame.size.height) } | |
} | |
var frameBottom: CGFloat { | |
get { frame.origin.y + frame.size.height } | |
set(newBottom) { frame = CGRectMake(frame.origin.x, newBottom - frame.size.height, frame.size.width, frame.size.height) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment