Cannot seem to use CGRectIntegral and CGRectInset functions in Swift

前端 未结 3 1372
星月不相逢
星月不相逢 2021-01-18 23:43

Sorry for the novice question.

But just as the title says, I can\'t seem to use these functions in Swift 3. I have tried by importing the CoreGraphics library, but to

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-19 00:25

    Actually you don't need to import CoreGraphics.

    In Swift 3 Objective-C function

    CGRect CGRectIntegral(CGRect rect)
    

    has become

    var integral: CGRect { get }
    

    and

    CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy);
    

    has become

    func insetBy(dx: CGFloat, dy: CGFloat) -> CGRect
    

    Both API have to be called on the CGRect instance for example

    let newFrame = view.frame.insetBy(dx: 10.0, dy:10.0)
    

    A hint to find out yourself

    • Press ⇧⌘0
    • Type CGRectIn in the search field
    • In the popup menu set the language to Objective C
    • Select one of the functions
    • Set the language to Swift

提交回复
热议问题