0

I'm using the workaround described here to vertically align text in a multiline UILabel to the top. Unfortunately that solves only half of the problem because I also want to collapse the remaining space and move other labels below the label to move up and consume the space.

Is there anyone way to achieve this without having to resort to calculating the Frame's of the other views yourself and thus taking over the layouting?

Here's a screenshot of my problem. To make it easier I've colored the background of the relevant labels. The Blue label is supposed to move up and consume the unused space of the red label. The Red Label is configured for 3 Lines and Font-Autoshrink is off.

Community
  • 1
  • 1
Oliver Weichhold
  • 10,259
  • 5
  • 45
  • 87

1 Answers1

1

You must re-calculate your label frames and then rearrange your labels in the view. Or you can try to use CoreText to make more complex layouts without the need to cope with these frames rearrangement. On GitHub there is a nice work BSD-licensed, called NSAttributedString+HTML: https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML which tries to port in the iOS the same methods already available in OSX. It is based on CoreText and with this class you can write your page as html and render it on screen without using UIWebView (and without its limitations). Based on your screenshot, it would be easy to achieve the wished result with simple html.

viggio24
  • 12,316
  • 5
  • 41
  • 34
  • So when positioning SubViews, iOS only takes their original locations and the Size Inspector Scaling settings into account but does not really layout controls in relation to neighboring SubViews? – Oliver Weichhold Nov 27 '11 at 08:50
  • No, unfortunately we cannot do that yet. What we can hope is that the new Lion autolayout feature will be ported to iOS... Infact the structs and springs method is quite limited and most of the cases you have to work with the layoutSubviews method. – viggio24 Nov 27 '11 at 12:41
  • Wow, when you are used to XAMLs powerful layout and binding system this feels like back in stone age. Thanks for sharing some insight. – Oliver Weichhold Nov 27 '11 at 12:56