I'm working on a project that requires creating a customizable sharing card (understand an image people can export to share on social media later).
I'm building these sharing cards as plain UIView that contains several other UI elements (UIImageViews and UILabels mostly).
Let's call it SharingCardView for simplicity.
Since this visual will be exported and shared, I need to have it look exactly the same on all devices. So my understanding is that I need to have the AutoLayout constraints have responsive constants based on the user's device screen size.
Imagine I display that UIView on an iPhone and then on an iPad, I want to have the aspect ratio of everything inside that SharingCardView maintained so people can't see any difference between a visual exported from an iPhone or an iPad.
### Question:
I would like to be able to pin a label to the top of the SharingCardView **with a constant of 10%**as shown on the screenshot below.
### So far I tried this way
I tried to set the constant to self.bounds.width * 0.1 but when I create my view bounds is apparently equal to zero so the constraint is just pinning everything at the very top without any padding.
nowUpOnYTLbl.anchor(top: topAnchor,
left: leftAnchor,
bottom: nil,
right: rightAnchor,
paddingTop: self.bounds.width * 0.1,
paddingLeft: 30,
paddingBottom: 0,
paddingRight: 30,
width: 0,
height: 20
)
Any suggestions would be super helpful. And if you think the approach is completely wrong then I'm all ears for alternative solutions.