1

I'm having a ImageView and a UILabel both aligned Top to Top.

They are next to each other so I have the label and then right of it the textview. Now when there is text in the label the text first letter is lower then the top of the ImageView. I want that the text first letter is always aligned to the top of the ImageView. So now I aligned the text -3 points to the top of the imageView and then it works. But I don't want to work with magic numbers.

This are the constraints I'm using

self.iconImageView.autoSetDimension(.Height, toSize: 10)
self.iconImageView.autoSetDimension(.Width, toSize: 10)
self.iconImageView.autoPinEdge(.Top, toEdge: .Top, ofView:self, withOffset: Constants.kMarginLarge)
self.iconImageView.autoPinEdge(.Left, toEdge: .Left, ofView:self, withOffset: Constants.kMarginNormal)

self.titleLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
self.titleLabel.autoPinEdge(.Top, toEdge: .Top, ofView: self.warningImageView, withOffset: -3)
self.titleLabel.autoPinEdge(.Left, toEdge: .Right, ofView:self.warningImageView, withOffset: 5)
self.titleLabel.autoPinEdge(.Right, toEdge: .Right, ofView:self, withOffset: -5)

Is there any way to calculate the offset and taking into account the First letter or something?

Screenshots:

enter image description here

user1007522
  • 7,858
  • 17
  • 69
  • 113
  • can you please share the screenshot of your requirement and what issue you are facing – Amit Singh Jun 28 '16 at 07:05
  • You have to remember that the labels frame is only a "bounding box" in which the text will be drawn. I.e. if you make the frame big enough and center the text it may not touch any of its edges. That in mind - have you tried setting `self.titleLabel.contentMode = .Top`? – Losiowaty Jun 28 '16 at 07:13
  • I've added a screenshot. I tried with contentMode Top but it stays the same. It is like you guys suggests it's the bounding box. – user1007522 Jun 28 '16 at 07:18
  • What happens if you don't pin the labels bottom edge? – Losiowaty Jun 28 '16 at 11:41
  • I can't do that. Because I'm using this in a cell with autolayout so the cell is auto sizing according to the text. – user1007522 Jun 29 '16 at 07:21

0 Answers0