0

I do this to add a Subview from Storyboard, which is a subview from a ViewController with its own Class. (TomStatusbarController) ...it is set as CustomClass in Storyboard. I do also Constraints with Layoutformats. This works fine, but the Statusbar is just red and i see no UIElements. I get lots on constraints warnings but it worked before, when i had it as an IBOutlet, but I have to change this now.

-(void)viewDidLoad {
 [super viewDidLoad];   
    if (self) {
        self.tomCaptureStatus = [[TomStatusbarController alloc] initWithFrame:CGRectMake(0, 0, 375, 78)];
        self.tomCaptureStatus.layer.bounds  = CGRectMake(0, 0, 375, 78);
        self.tomCaptureStatus.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
        self.view.translatesAutoresizingMaskIntoConstraints  = YES;

        self.tomCaptureStatus.backgroundColor = [UIColor redColor];

        [self.view addSubview:self.tomCaptureStatus];
        [self.view superview];
    }
}

So why i don't see any thing, expect my backgroundcolor?

Tom

peakme
  • 19
  • 4
  • why did you add [self.view superview]; – yoshiiiiiiii Jul 28 '17 at 10:18
  • what do you want to achieve? A coloured background behind the status bar i.e. a view of screen width x 20 px? – Johnny Rockex Jul 28 '17 at 10:28
  • Red color just for debugging. Superview for the Layoutformat. They need a superview to setup its constraints. – peakme Jul 28 '17 at 10:42
  • The TomnStatusbarController is part of a ViewController, which is embeded of a NavigationController… …is that a thing? – peakme Jul 28 '17 at 10:50
  • 3 remarks: 1. Never perform any UI-related tasks in viewDidLoad, because the UI elements are not properly laid out in viewDidLoad; Do it in viewDidLayoutSubviews instead. 2. From you code, I can see that TomStatusbarController is a subclass of UIView, and for UIView's subclasses, TomStatusbarController is a very bad naming. 3. The conditional statement if (self) is redundant. – hoang Cap Jul 28 '17 at 18:10
  • thx! @hoang Cap – peakme Jul 29 '17 at 14:51

0 Answers0