'Simple function for a customised label

I'm trying to write a most basic function that will set the parameters of a label.

First I set the position where I want to put a label:

var xCircularPos = UIScrollView.frame.width / 2
var yCircularPos = UIScrollView.frame.height * 0.15
    

And than write a function:

        func textParameters(labelName: UILabel, text: String, xPosition: CGFloat, yPosition: CGFloat) {
            
            labelName.textAlignment = .center
            labelName.text = text
            labelName.sizeToFit()
            labelName.layer.position.x = CGFloat(0)
            labelName.layer.position.y = CGFloat(0)
            UIScrollView.addSubview(labelName)
            
        }

Than I create a label and use a function:

    let scoreLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 21))
    textParameters(labelName: scoreLabel, text: "Счет", xPosition: xCIrcularPos, yPosition: yCIrcularPos)

But nothing happens. When I set the same parameters for the label without a function - everything works fine. In both cases everything happens in viewDidLoad.

Can you please give a tip what I am missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source