extension UIView {
func setX(_ x: CGFloat) {
let frame: CGRect = self.frame
frame.origin.x = x
self.frame = frame
}
func x() -> CGFloat {
return frame.origin.x
}
func setY(_ y: CGFloat) {
let frame: CGRect = self.frame
frame.origin.y = y
self.frame = frame
}
func y() -> CGFloat {
return frame.origin.y
}
func setCenterX(_ centerX: CGFloat) {
var center: CGPoint = self.center
center.x = centerX
self.center = center
}
func centerX() -> CGFloat {
return center.x
}
func setCenterY(_ centerY: CGFloat) {
var center: CGPoint = self.center
center.y = centerY
self.center = center
}
func centerY() -> CGFloat {
return center.y
}
func setWidth(_ width: CGFloat) {
let frame: CGRect = self.frame
frame.size.width = width
self.frame = frame
}
func width() -> CGFloat {
return frame.size.width
}
func setHeight(_ height: CGFloat) {
let frame: CGRect = self.frame
frame.size.height = height
self.frame = frame
}
func height() -> CGFloat {
return frame.size.height
}
func setSize(_ size: CGSize) {
var frame: CGRect = self.frame
frame.size = size
self.frame = frame
}
func size() -> CGSize {
return frame.size
}
}
网友评论