devicekit / DeviceKit

DeviceKit is a value-type replacement of UIDevice.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Device family based on the inch of the screen

furiosFast opened this issue · comments

Hello,
first of all, excellent library !!
I am writing to ask you if it would be possible to add support to the device family based on the inch of the screen, for example:
if Device.current.has4Inch {}
thanks

@furiosFast Did you find a solution to this?

@karthisiva hi, not for now

@furiosFast
You could check against Device.current.diagonal

if Int(Device.current.diagonal) == 4 {
    // Your code
}

The conversion to Int is because of floating point precision. If you would check for Device.iPhone12Pro.diagional (which is 6.1), you would have to convert it to a string and check against that value because it's not a round number.

if String(format: "%.1f", Device.current.diagonal) == "6.1" {
    // Your code
}

public var diagonal: Double {


Actually implementing functions with Device.current.has4InchScreen would clutter up the API very much because of the great number of different screen sizes there are.