0

I have a popover which shows a UIViewController containing a UIView and a UILabel. I want the popover to grow/shrink to the size of the content of the UILabel. How do I do that? Here is the part of the UIViewController in the popover which now determines it's size...

#pragma mark - View controller life cycle

- (CGSize)preferredContentSize {
    return self.view.frame.size;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    _personNameLabel.text = self.person.fullNameWithTitle;
}

What do I need to do to have the popover to show the person's name and size itself to the size of the name?

Indrajeet
  • 5,490
  • 2
  • 28
  • 43
Tycho Pandelaar
  • 7,367
  • 8
  • 44
  • 70
  • calculate width and height and set this `self.contentSizeForViewInPopover = CGSizeMake(width,height);`//for iOS 6 for `iOS7` use this `self.preferredContentSize = CGSizeMake(width,height);` set this in `viewDidLoad` or in `viewWillAppear` method – Shankar BS Jul 31 '14 at 11:02

1 Answers1

0

Calculate width and height and set this,

For iOS 6,

self.contentSizeForViewInPopover = CGSizeMake(width,height);

For iOS7,

self.preferredContentSize = CGSizeMake(width,height); 

set this in viewDidLoad or in viewWillAppear method.

itsji10dra
  • 4,603
  • 3
  • 39
  • 59
Tycho Pandelaar
  • 7,367
  • 8
  • 44
  • 70