How can I increase the size of a CGRect by a certain percent value?

后端 未结 7 2020
春和景丽
春和景丽 2021-02-12 14:22

How can I increase the size of a CGRect by a certain percent value? Should I use some form of CGRectInset to do it?

Example:

Assume I have a CGRect:

7条回答
  •  粉色の甜心
    2021-02-12 14:52

    I'm using CGRect > insetBy in my Swift code

    https://developer.apple.com/documentation/coregraphics/cgrect/1454218-insetby

    With this, your percent value will be the scaleX as my example.

        let dx = rectWidth*scaleX
        let dy = rectHeight*scaleX
        let rectangle = CGRect(x: rectX,
                               y: rectY,
                               width: rectWidth,
                               height: rectHeight).insetBy(dx: -dx, dy: -dy)
    
    • use positive value to scale down
    • use negative value to scale up

提交回复
热议问题