0

I tried to change UILabel.frame with a button and it works correctly:

  - (IBAction)changeSize:(id)sender
    {
        CGRect rec = self.labelHello.frame;
        rec = CGRectMake(20, 20, 280, 300);
        self.labelHello.frame = rec;
    }

But if I use the same code in viewDidLoad has no effect.

 - (void)viewDidLoad
    {
        [super viewDidLoad];

        CGRect rec = self.labelHello.frame;
        rec = CGRectMake(20, 20, 280, 300);
        self.labelHello.frame = rec;
    }

Someone can help me?

Thank's Stefano

kirti Chavda
  • 3,029
  • 2
  • 17
  • 29
  • try it in the viewWillAppear: method. – Franck Sep 21 '13 at 09:17
  • 1
    @Stefano How you are having label in your view by XIB or by programming? If through XIB you need to do this when your view gets loaded and appears in `viewWillAppear` or if through programming just write this code below the allocation code for the label. – Mayur Shrivas Sep 21 '13 at 09:20
  • Unfortunately it does not work with viewDidAppear but instead works correctly with viewDidAppear. Thank's a lot! Stefano – Stefano Sep 21 '13 at 10:15

2 Answers2

1

you can cheat with dispatch_async:

- (void)viewDidLoad
{
    [super viewDidLoad];

    dispatch_async(dispatch_get_main_queue(), ^{
        CGRect rec = self.labelHello.frame;
        rec = CGRectMake(20, 20, 280, 300);
        self.labelHello.frame = rec;
    });
}
kambala
  • 2,341
  • 19
  • 20
0

Try this code in viewwillAppear..it will work...

mani murugan
  • 213
  • 2
  • 12
  • Unfortunately it does not work with viewDidAppear but instead works correctly with viewDidAppear. Thank's a lot! – Stefano Sep 21 '13 at 10:20