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

后端 未结 7 2021
春和景丽
春和景丽 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 15:01

    let scale = percent / 100
    let newRect = oldRect.applying(CGAffineTransform(scaleX: scale, y: scale))
    

    Beware that this approach also will change x and y of rectangle.

提交回复
热议问题