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

后端 未结 7 2014
春和景丽
春和景丽 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.

    0 讨论(0)
提交回复
热议问题