I'm using Swift to display some text in the middle of the screen, but I'm doing this programmatically instead of using the layout designer. So I'm starting with my version of a UILabel:
class GenericLabel: UILabel
I'm then creating one of these objects:
let label = GenericLabel(frame: CGRect.zero)
label.processResponse(componentDictionary )
view.addSubview(label)
The processResponse function will set the text value, the font, fontsize, and set the bounds for where the text should be displayed on the screen. Currently I'm just wanting to position the text in the centre of the screen. During this process I send some messages to the console, like my calculation of the width and height and the bounds value. The console includes this:
GenericLabel: default = centrex and centrey
Utils:setSize: parent view bounds = (0.0, 0.0, 402.0, 874.0)
Utils:setSize: obj size = (85.33333333333333, 20.333333333333332)
Utils.setSize: centrey myframe.origin.y = 426.8333333333333
Utils.setSize: centrex myframe.origin.x = 158.33333333333334
Utils:setSize: myframe is now set to = (158.33333333333334, 426.8333333333333, 85.33333333333333, 20.333333333333332)
self.frame set to (158.33333333333334, 426.8333333333333, 85.33333333333333, 20.333333333333332)
Finally I set this frame to my GenericLabel
self.frame = Utils.setSize(["centrex":0, "centrey":0], for: self)
// You can see this message in the console above
print("self.frame set to \(self.frame)")
Unfortunately the text appears at (0,0) as in this screenshot.
Why is the frame not working? Is there some setting overriding the frame?