Can I adjust a CGRect with a UIEdgeInsets?

后端 未结 4 665
故里飘歌
故里飘歌 2020-12-08 13:30

I\'ve got a CGRect, and I\'d like to adjust it with a UIEdgeInsets.

It seems like perhaps there might be a built in function that does this

4条回答
  •  天命终不由人
    2020-12-08 14:02

    2018 ... Swift4

    Say you want the bounds,

    but for example less two pixels on the bottom:

    let ei = UIEdgeInsetsMake(0, 0, 2, 0)   // top-left-bottom-right
    let smaller = UIEdgeInsetsInsetRect(bounds, ei)
    

    That's it.

    If you prefer to write it as one line, it's just

    Take two off the bottom:

    let newBounds = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(0, 0, 2, 0))
    

    Cheers

提交回复
热议问题