Вы будете намного лучше учиться / использовать ограничения и автоматическое размещение.
Вот то, что вы пытаетесь сделать, но это будет автоматическое расположение правильно для всех различных устройств и поворотов:
_noExperiences = [UIView new];
_noExperiences.backgroundColor = [UIColor whiteColor];
UILabel *nothingToShow = [UILabel new];
nothingToShow.text = @"HELLO";
nothingToShow.textColor = [UIColor blackColor];
nothingToShow.textAlignment = NSTextAlignmentCenter;
[nothingToShow setNumberOfLines: 0];
[nothingToShow setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
// add _noExperiences to self.view
[self.view addSubview:_noExperiences];
// add nothingToShow to _noExperiences
[_noExperiences addSubview:nothingToShow];
// we'll use auto-layout, so set to NO
_noExperiences.translatesAutoresizingMaskIntoConstraints = NO;
nothingToShow.translatesAutoresizingMaskIntoConstraints = NO;
// let's respect safe area
UILayoutGuide *g = self.view.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[
// constrain _noExperiences view to safe area
[_noExperiences.topAnchor constraintEqualToAnchor:g.topAnchor constant:0.0],
[_noExperiences.bottomAnchor constraintEqualToAnchor:g.bottomAnchor constant:0.0],
[_noExperiences.leadingAnchor constraintEqualToAnchor:g.leadingAnchor constant:0.0],
[_noExperiences.trailingAnchor constraintEqualToAnchor:g.trailingAnchor constant:0.0],
// constrain nothingToShow label centered in _noExperiences view
[nothingToShow.centerXAnchor constraintEqualToAnchor:_noExperiences.centerXAnchor],
[nothingToShow.centerYAnchor constraintEqualToAnchor:_noExperiences.centerYAnchor],
]];
РЕДАКТИРОВАТЬ
Если вы действительно необходимо поддерживать 7 пользователей, которые используют iOS версию ранее 11, вы можете попробовать это для обработки пропавшего safeAreaLayoutGuide
:
// let's respect safe area for iOS 11+
// or layoutMarginsGuide for earlier
UILayoutGuide *g;
CGFloat standardSpacing = 0.0;
if (@available(iOS 11, *)) {
// iOS 11 (or newer) ObjC code
g = self.view.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[
// constrain _noExperiences view to safe area
[_noExperiences.topAnchor constraintEqualToAnchor:g.topAnchor constant:0.0],
[_noExperiences.bottomAnchor constraintEqualToAnchor:g.bottomAnchor constant:0.0],
[_noExperiences.leadingAnchor constraintEqualToAnchor:g.leadingAnchor constant:0.0],
[_noExperiences.trailingAnchor constraintEqualToAnchor:g.trailingAnchor constant:0.0],
]];
} else {
// iOS 10 or older code
standardSpacing = 8.0;
g = self.view.layoutMarginsGuide;
[NSLayoutConstraint activateConstraints:@[
// constrain _noExperiences view to layout margins guide
[_noExperiences.topAnchor constraintEqualToAnchor:g.topAnchor constant:standardSpacing],
[_noExperiences.bottomAnchor constraintEqualToAnchor:g.bottomAnchor constant:-standardSpacing],
[_noExperiences.leadingAnchor constraintEqualToAnchor:g.leadingAnchor constant:0.0],
[_noExperiences.trailingAnchor constraintEqualToAnchor:g.trailingAnchor constant:0.0],
]];
}
[NSLayoutConstraint activateConstraints:@[
// constrain nothingToShow label centered in _noExperiences view
[nothingToShow.centerXAnchor constraintEqualToAnchor:_noExperiences.centerXAnchor],
[nothingToShow.centerYAnchor constraintEqualToAnchor:_noExperiences.centerYAnchor],
]];