Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The left side of the square is clearly centered on the screen, so that the current code runs correctly. In order for the square itself to be centered along the X axis, you need to additionally move it to the left by half its width. That is, the code should be like this:
dateNow.frame = CGRect(x: screen.width/2 - screen.width/3/2 , y: 50, width: screen.width/3 , height: screen.height/4)
Apple recommends using Autolayout, not frames, and there are bindings to the central axes: NSLayoutAttributeCenterX, NSLayoutAttributeCenterY, you can add offsets for them. Moreover, you can do this both in IB (storyboard or xib), and in code using VFL (Visual Format Language).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question