Cannot seem to use CGRectIntegral and CGRectInset functions in Swift

前端 未结 3 1373
星月不相逢
星月不相逢 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:04

    The functions are working fine, but their names have changed (a bit):

      let frame = CGRect.zero
      let x = frame.integral
      frame.insetBy(dx: 0, dy: 0)
    
    0 讨论(0)
  • 2021-01-19 00:14
    1. import CoreGraphics

    2. let rect = CGRect() let rectIntegral = rect.integral

    Thanks:)

    0 讨论(0)
  • 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
    0 讨论(0)
提交回复
热议问题