Search code examples
iosobjective-cconstraintsaddsubview

iOS addView: Adds view from story board without constraints


I have a View in the Storyboard, which shows an error message. I remove this at load using

[self.ErrorView removeFromSuperView];

Later on in the code, I then want to show the view, using

[self.MainView addSubview:self.ErrorView];

this does show the view, but the view is only sized by the content within in, where as on the story board it is size to full width using the 'Leading/Trailing Edge' constraints.

How do I refresh the view's constraints to match those on the storyboard.


Solution

  • As far as I understood, you want to only show and hide view in UIViewController? If that is your purpose you should use this code:

    self.ErrorView.hidden = YES;  // To hide alert
    

    and

    self.ErrorView.hidden = NO;  // To show alert