Reputation: 12857
I have a SubView inside another View that has other elements inside it. I horizontally centered the middle element of SubView to SubView, but I need to give it an extra horizontal offset. Is there a way to be able to use both Horizontal Center and give extra offset?
Unfortunately, this isn't work:
override func viewDidLoad() {
super.viewDidLoad()
MyView.frame.origin.x += 50
}
Upvotes: 0
Views: 32
Reputation: 14040
you were already heading into the right direction...
override func viewDidLoad() {
super.viewDidLoad()
let frame = MyView.frame
frame.origin.x += 50
MyView.frame = frame
}
if you are using autolayout though you have to modify constraints instead of modifying frames directly.
Upvotes: 0
Reputation: 12617
Just change the constant value from 0 to 50 (or any value of choice) to give an offset to horizontal alignment.
See picture below:
Upvotes: 1