-2

enter image description hereenter image description here

I want my button to be 20pts from the left and 20pts from the top. It looks great on the iphones prior to the notch. How can I constraint this button to the top of the screen? So it will look symmetrical from the left and top. Thank you in advance.

Captain Dilan
  • 71
  • 1
  • 6

1 Answers1

1

you can wire your button from the top with superView not safe area. you can do this by clicking on the top constraint for the button, and from the inspect menu on the right on Xcode change the second item to superView

omartarek32
  • 179
  • 6
  • do not forget to update your constraint constant after doing this – omartarek32 Apr 30 '20 at 15:56
  • can you please share a screenshot? – omartarek32 Apr 30 '20 at 16:20
  • i added it to the post – Captain Dilan Apr 30 '20 at 16:26
  • `So it will look symmetrical from the left and top.`, if you set pts 20 both left and top then it conflicts with time at the top left on the screen – Kishan Bhatiya Apr 30 '20 at 16:30
  • So what should I change? – Captain Dilan Apr 30 '20 at 16:50
  • it is better to display components within `safeArea` of the screen with align top and leading to safe Area – Kishan Bhatiya Apr 30 '20 at 16:53
  • so can I set a different constraint for iphonex phones – Captain Dilan Apr 30 '20 at 17:04
  • I think I got the problem, you may check for top Constraint for the super view of Label. i.e. the view which contain your label. it may still wired to SafeArea, it should be wired to super view as well @Captaionddfsdf – omartarek32 Apr 30 '20 at 21:02
  • you can add constraint to iPhoneX only, but it is bad Idea. but briefly, you can do this as the following. 1- you need to check your device model, you can do this using extension in this like https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model 2- you add your constraint programmatically. but I do not recommend this solution. it is not a good practice @Captaionddfsdf – omartarek32 Apr 30 '20 at 21:07