Reputation: 51261
I would like to use the same nib file for both iPad and iPhone.
I found there are two black bars in the top and bottom when I run the app on iPhone 6 plus. So I found there is a fixed size defined in my xib file, and they are not editable.
How should I make it adapt to different screen size?
Note: * The project doesn't use autolayout and storyboard
Upvotes: 1
Views: 3069
Reputation: 7207
On viewWillAppear
set frame of your xib file.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.view.frame = UIScreen.main.bounds
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self view] setFrame:[[UIScreen mainScreen] bounds]];
}
Upvotes: 5
Reputation: 5369
You have to unable all the Auto Resizing masks at XIB
In ur picture, u also need to set Width & Height Auto Resizing masks..So that the xib/view will take the width & Height as per super view or fill the screen.
For more info about Auto Resizing Masks refer below link..
Autoresizing masks programmatically vs Interface Builder / xib / nib
Hope it helps you..
Upvotes: -2
Reputation: 4040
There is no way around it, you need to use autolayout and size classes: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html
You can use nib files, that's fine, but autolayout and size classes are unavoidable if you're going to make an app for all devices.
Upvotes: 2