Ask Your Question
3

In Swift, what is the programming method for determining the screen size of an iPhone 4 or iPhone 5?

asked 2022-05-05 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-25 12:00:00 +0000

pufferfish gravatar image

In Swift, you can determine the screen size of an iPhone 4 or iPhone 5 by checking the bounds of the UIScreen object. Here's an example code snippet that shows how to do this:

let screenSize = UIScreen.main.bounds.size
if screenSize.height == 480 {
   print("iPhone 4 screen size")
} else if screenSize.height == 568 {
   print("iPhone 5 screen size")
} else {
   print("Not an iPhone 4 or 5")
}

This code first gets the size of the main screen using the bounds property of the UIScreen object. It then checks the height of the screen size, and if it matches the height of either iPhone 4 or 5, it prints the appropriate message.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-05 11:00:00 +0000

Seen: 12 times

Last updated: Apr 25 '22