2020-07-24 19:26:35 -07:00
|
|
|
//
|
|
|
|
|
// CGPoint+Utils.swift
|
|
|
|
|
// SBrowser
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 7/23/20.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
extension CGRect
|
|
|
|
|
{
|
|
|
|
|
var center: CGPoint {
|
|
|
|
|
get {
|
|
|
|
|
return CGPoint(x: size.width / 2.0, y: size.height / 2.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-29 14:16:25 -07:00
|
|
|
|
|
|
|
|
public func avoiding(verticalInsets insets: UIEdgeInsets) -> CGRect {
|
|
|
|
|
var rect = self
|
|
|
|
|
rect.origin.y += insets.top
|
|
|
|
|
rect.size.height -= insets.top
|
|
|
|
|
|
|
|
|
|
return rect
|
|
|
|
|
}
|
2020-07-29 17:46:53 -07:00
|
|
|
|
2021-06-14 18:09:33 -07:00
|
|
|
public func subtracting(width: CGFloat, height: CGFloat) -> CGRect {
|
|
|
|
|
var rect = self
|
|
|
|
|
rect.size.width -= width
|
|
|
|
|
rect.size.height -= height
|
|
|
|
|
|
|
|
|
|
return rect
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-29 17:46:53 -07:00
|
|
|
public func centeredY(inRect: CGRect) -> CGRect {
|
|
|
|
|
var rect = self
|
2025-04-11 18:27:59 -07:00
|
|
|
rect.origin.y = (inRect.origin.y + (inRect.height - rect.height) / 2.0).rounded()
|
2020-07-29 17:46:53 -07:00
|
|
|
|
|
|
|
|
return rect
|
|
|
|
|
}
|
2020-08-14 15:55:08 -07:00
|
|
|
|
|
|
|
|
public func centeredX(inRect: CGRect) -> CGRect {
|
|
|
|
|
var rect = self
|
2025-04-11 18:27:59 -07:00
|
|
|
rect.origin.x = (inRect.origin.x + (inRect.width - rect.width) / 2.0).rounded()
|
2020-08-14 15:55:08 -07:00
|
|
|
|
|
|
|
|
return rect
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func centered(inRect: CGRect) -> CGRect {
|
|
|
|
|
self.centeredX(inRect: inRect).centeredY(inRect: inRect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension CGSize
|
|
|
|
|
{
|
|
|
|
|
public func extendingBy(dw: CGFloat, dh: CGFloat) -> CGSize {
|
|
|
|
|
var ourSize = self
|
|
|
|
|
ourSize.width += dw
|
|
|
|
|
ourSize.height += dh
|
|
|
|
|
|
|
|
|
|
return ourSize
|
|
|
|
|
}
|
2020-07-24 19:26:35 -07:00
|
|
|
}
|