how to use values returned by Swift function

前端 未结 5 410
不思量自难忘°
不思量自难忘° 2021-01-26 01:36

I am trying to use a Swift function to place a circle in the centre of a view so it is always on centre regardless of screen size. I can draw the circle at a point defined by a

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 02:10

    Your screenCenter function returns a tuple containing two CGFloat values. These values are labeled x and y so you can access them by name when querying the function’s return value.

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let center = screenCentre()
        //center.x contains the x value returned from screenCenter
        //center.y contains the y value returned from screenCenter
    
        circle(x: center.x , y: center.y)
    }
    

提交回复
热议问题