Reputation: 1195
I need to display some text in UIView for which I use label. I am using a xib file. What I need as alignment:
Is it possible to do this? I don't have enough experience with the interface builder.
Upvotes: 1
Views: 60
Reputation: 36
1) apply required autolayout for label and take 3 NSLayoutConstraint IBOutlets attributes, they are 1) Label width 2) label height 3)label y Origin.
2) calculate label width let say Label width Constraint Name is: lblWidthConstraint
**CGFrame screenFrame = [UIScreen mainScreen].bounds;**
**if(screenframe.size.width>200){
self.lblWidthConstraint.constant = 200;
}else{
self.lblWidthConstraint.constant = screenframe.size.width-6;//
}**
3) calculate label Height let say Label height Constraint Name is: lblHeighthConstraint
Based on Label fixed width and Fixed Text find the Label Height, here Max Height should be
CGFloat height = screenframe.size.height-2*(buttonHeight+spacing); self.lblHeighthConstraint.constant = height;
4)calculate label Y Orgin let say Label Y Origin Constraint Name is: lblHeighthYorigin
Based On LabelHeight we should Calculate the Label y origin
yOrign = screenframe.size.height-height/2; self.lblHeighthYorigin.constant = yOrign;
Upvotes: 2
Reputation: 6112
Use the alignement contraints for center.
Use the Aspect Ration for the size.
-> Set Aspect ration height = % of the width and a max width of 200px
Use the SizeClass to set another contraint size for screens lesser than 500px. Do it as many time you have screen size different layout.
Upvotes: 1