Dear friend, the idea is that autoLayout really helps you, but as your question was to know what type of device, follows the answer:
You can determine the device as follows:
To facilitate I will create 2 structs.
This first dynamically picks up the width and height of the device, determining max and min:
public struct ScreenSize{
static let SCREEN_WIDTH = UIScreen.main.bounds.size.width
static let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}
This second already has the rules to determine the type of device used:
public struct DeviceType
{
static let IS_IPHONE_4_OR_LESS = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
static let IS_IPHONE_5 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
static let IS_IPHONE_6 = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
static let IS_IPHONE_6P = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
static let IS_IPHONE_X = UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH == 812.0
}
An example of its use would be:
if DeviceType.IS_IPHONE_4_OR_LESS {
// 4S ou anterior
}
Static constants were created to facilitate their use in their classes.
Tiago, it would be interesting for you to add some visual examples of what happens and excerpts of code to better understand the problem. About your question, I believe that the sizeToFit function can solve your problem
– Lucas Eduardo
I’ll take a look at this function.. follows the rendering image in ipads. Thank you!
– Tiago Segato