0

I am pretty new to iOS dev. I am trying to create a view with a UILabel and a UITableView. The UILabel is used to display some header text & the tableview is positioned below the header & it covers the remaining portion of the screen.

I am creating this view using code & not the storyboard approach. So I need to specify the height & width of my tableview as constraints. For the width I have set a constraint where it matches the width of the container view. However for the height I wish to use the following equation:

tableview's height = container view's height - UILabel's height

For this I need to know how I can get the container's & the UILabel's height via code. I tried the following approach-

CGFloat header_height=lblHeader.bounds.size.height;

But this gives the same height as the container view's height .i.e. 460. Can someone please explain how I can get the height of the UIlabel view?

Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
user1122549
  • 664
  • 1
  • 13
  • 27
  • Do you create the UILabel programmatically? When are you creating these? Add some code... By the way, if you are counting on some frame of view from storyborad (even self.view), this will be valid only after viewDidAppear. – oren May 01 '15 at 12:31

1 Answers1

1

To get the height of the UILabel do this instead:

CGFloat header_height = lblHeader.frame.size.height;

Frames and bounds are not the same.

Cocoa: What's the difference between the frame and the bounds?

Community
  • 1
  • 1
Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36