Tech-Today
How to differentiate between 3.5 and 4 inch iPhone
Open Xcode and create a new Single View Application. For product name, use DifferentiateIphoneSize and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices.
For demonstration purposes, add a label inside the view controller and change the text to "3.5-inch or 4-inch".
We will need to connect the label to the view controller. Select the assistant editor and open the ViewController.m file. Ctrl and drag from the label to the class section and create the following outlet.
Inside the viewDidLoad, add the following lines of code:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
if([UIScreen mainScreen].bounds.size.height == 568){
// iPhone retina-4 inch
self.lbl_textOutput.text = @"iPhone retina-4 inch";
} else{
// iPhone retina-3.5 inch
self.lbl_textOutput.text = @"iPhone retina-3.5 inch";
}
}
else {
// not retina display
self.lbl_textOutput.text = @"iPhone that's not retina display";
}
}
Build and Run, a label can be seen with text "iPhone retina-4 inch" if the app is run in with 4-inch size, otherwise "iPhone retina-3.5 inch".
You can download the source code of the DifferentiateIphoneSize at my repository on
bitbucket.
-
Create A Simple Table View App In Xcode
Open Xcode and create a new Single View Application. For product name, use SimpleTableView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a table view inside the view controller....
-
Xcode How To Read Raw Data From Pipe-delimited Text File
Open Xcode and create a new Single View Application. For product name, use ReadPipeDelimitedTextfield and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. I have prepared a text file to...
-
Xcode: Create A Simple Alertview
Open Xcode and create a new Single View Application. For product name, use SimpleAlertView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a button inside the view controller...
-
Display Time Picker On Textfield Click In Xcode
Open Xcode and create a new Single View Application. For product name, use TextFieldTimePicker and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. For setting up the user interface, first,...
-
Webview Tutorial In Ios 8 With Swift
The UIWebView class is use to embed web content in an application. It can be done by simply creating a UIWebView object and attaching it to a window and then sending it a request to load web content. Open Xcode and create a new Single View Application....
Tech-Today