Category: Xcode

Xcode 9 iOS icon sizes
December 17th, 2017 by ronny

Xcode 9 iOS icon sizes overview

Xcode 9 iOS icon sizes overview. They keep adding more and more icon sizes. Xcode 9 has the most icon sizes so far. No wonder since it is the version supporting the most iOS versions and iOS devices. Every iPhone since iPhone 5 and a bunch of iPads and iPods is supported. Many of the different devices have their own screen resolution and screen size. That requires a lot of different resolutions for their icons. Below is a complete list of all the different icon sizes you need to upload your app to App Store. Yes, you need them all.

I used to make an icon at 1024×1024 pixels, and just edit the resolution for all the different sizes in Photoshop. That is quite tedious work. If you cant be bothered to do that your self, jump to the end of this article where there is a short-cut.

Remember this

If you look at the icon form in Xcode where you put all the icons, there are some sizes listed. First time I created an app, I thought that was the size of the icons. It is the size, but not in pixels. They call it points. So if you see 29pt and under the icon, it says 2x. That means 29×2 pixels which should be 58×58 pixels. Here we go with the Xcode 9 iOS icon sizes.

Xcode 9 iOS icon sizes

xcode 9 ios icon sizes

iPhone Notification iOS 7-11
20pt – 2x – 40×40
20pt – 3x – 60×60

iPhone Spotlight iOS 5,6 & Settings iOS 5-11
29pt – 2x – 58×58
29pt – 3x – 87×87

iPhone Spotlight iOS 7-11
40pt – 2x – 80×80
40pt – 3x – 120×120

iPhone App iOS 7-11
60pt – 2x – 120×120
60pt – 3x – 180×180

iPad Notification iOS 7-11
20pt – 1x – 20×20
20pt – 2x – 40×40

iPad Settings iOS 5-11
29pt – 1x – 29×29
29pt – 2x – 58×58

iPad Spotlight iOS 7-11
40pt – 1x – 40×40
40pt – 2x – 80×80

iPad App iOS 7-11
76pt – 1x – 76×76
76pt – 2x – 152×152

iPad Pro App iOS 9-11
83,5pt – 2x – 167×167

App Store iOS
1024pt – 1x – 1024×1024

Shortcut

That’s all the icons sizes you need to publish your app in the App Store. As I promised at the beginning of the articles, here is a shortcut to your app icons sizes. You create one icon at 1536×1536 pixels and head over to MakeAppIcon. There you upload your one icon, the site process the icon and sends you an email with a link to download all the correct sizes you need. Saves you a ton of time. They even sell a MacOS app to create the icons for you. For me, the site does a good enough job.

You might find something interesting on my YouTube channel as well.

Check this if you are looking for the Xcode 8 icons.

Enjoy and happy app publishing!

Posted in Mac, Programming, Xcode Tagged with: , ,

Xcode 9 uiimage image not shown
September 30th, 2017 by ronny

Xcode 9 uiimage image not shown

Working on some ios apps created with Xcode 8 and your images don’t show after upgrading to Xcode 9? Took me awhile to find out why. Maybe you see this message in the console: “Could not load the image referenced from a nib in the bundle with identifier”.

Xcode 9 uiimage image not shown because Xcode 9 wants you to keep all your image files inside the Assets.xcassets file. Uiimage will let you select image files outside the Assets, but will make the uiimage control to not show at all.

If Xcode 9 uiimage image not shown move your images inside the Assets file, select the image again in the uiimage properties and give it another go. That worked for me.

Also, read Swift Change UIButton text

 

Happy coding!

Posted in Swift, Xcode Tagged with: ,

April 3rd, 2017 by ronny

Xcode 8 iOS icon sizes overview

Xcode 8 iOS icon sizes overview. There are even more icon sizes since Xcode 7. And it can be an extra challenging with all those different resolutions. Current Xcode (version 8), supports all iPhones since 4s, most iPods, and most iPads. You will need quite a few different icons sizes. That’s what I will list up here. A complete list of all different sizes for the different icons needed for an iOS application used today.

If you are looking for the Xcode 7 overview, please go to Xcode 7 iOS Icon sizes overview

If you are looking for the Xcode 9 overview, please go to Xcode 9 iOS Icon sizes overview

Xcode 8 iOS icon sizes overview – 17 icons

Xcode 8 iOS icon sizes

Just remember….

If you look at the picture above, you will see something like 29pt under the iPhone spotlight icon. First time I believed that was the icons size. And it is. But not in pixels. Above you see two empty icon windows saying 2x and 3x. That means 29 x 2 for the first window (58×58 pixels) and 29 x 3 for the second icon (87×87 pixels). Just multiply the pt value with x value, and you have the size in pixels. I usually create the largest icon (1024×1024 and uses photoshop (or any other image editing software) to make the smaller resolutions out of the biggest one.

Anyway, below you will find the list for the latest Xcode from when this article was written.

Icon Size list

Xcode 8 iOS icon sizes

iPhone Notification iOS 7-10
20pt – 2x – 40×40
20pt – 3x – 60×60

iPhone Spotlight iOS 5,6 & Settings iOS 5-10
29pt – 2x – 58×58
29pt – 3x – 87×87

iPhone Spotlight iOS 7-10
40pt – 2x – 80×80
40pt – 3x – 120×120

iPhone App iOS 7-10
60pt – 2x – 120×120
60pt – 3x – 180×180

iPad Notification iOS 7-10
20pt – 1x – 20×20
20pt – 2x – 40×40

iPad Settings iOS 5-10
29pt – 1x – 29×29
29pt – 2x – 58×58

iPad Spotlight iOS 7-10
40pt – 1x – 40×40
40pt – 2x – 80×80

iPad App iOS 7-10
76pt – 1x – 76×76
76pt – 2x – 152×152

iPad Pro App iOS 9-10
83,5pt – 2x – 167×167

iTunes Connect
App Icon – 1024×1024

Thats it about iOS icon sizes.

To read more about the subject, check out Apples Xcode documentation.
Or maybe check out my youtube channel.

Happy iconising!

Posted in Mac, Programming, Xcode Tagged with: , ,

Swift Capitalize
April 2nd, 2017 by ronny

Swift Capitalize, How to

Swift Capitalize is done with a string instance property. Check the example below to see how to use it. There is also a link at bottom to Apples Swift documentation.
let str = “first, second, third”
print(str.capitalized)

This will output: First, Second, Third

Swift Capitalize

It will capitalize every word in this string. Lets remove the commas and see what happens.

Change str = “first second third”

The output now will be: First Second Third

Check Apple Swift Capitalizion documentation for more information about the string instance property.

Swift Capitalizion
Produce a string with the first character from each word changed to the corresponding uppercase value.

Posted in Swift, Xcode Tagged with: ,

didMove never get called
March 11th, 2017 by ronny

didMove never get called in Xcode?

didMove never get called when creating a new project with Xcode using the Game template. I selected Swift and SpriteKit. I found this issue when I was following a course on Udemy.com, and I couldn’t get a simple project to run like in the course videos. Creating a new project after deleting the one I was working on, after trying to debug the error, gave me the same result. didMove never get called. I did only one change to the project created with game template. That was to put in print(“didMove did run”). But it never was.

The only way I would get the didMove to run was calling the scene like this in the GameViewController.
let scene = MainMenuScene(size: CGSize(width: 1536, height: 2048))

Tried to google, and I found this one post on Stack Overflow with the same issue. He said it was caused by a period in his project name. Crazy, but I did use a – in my project name. Was only a test project, so calling it physics-test was not a good idea. I renamed it to PhysicsTest, and the didMove was called.

Not sure if it is a language setting issue or anything. I’m using english language and Norwegian region settings on my computer. Not sure if that got anything to do with it, but in the tutorial video I was following it worked great using – in the project name.

Anyway, if you experience didMove never get called in Xcode, it might be worth removing any non letter and number characters.

Happy coding!

Posted in Swift, Xcode Tagged with: , ,

Swift Change UIButton text
June 9th, 2016 by ronny

Swift Change UIButton text

How to in Swift change UIButton text?
A common mistake, also done by myself some time ago, is to try to change it through an IBAction. You can use an IBAction, but probably not the way you think. A common mistake is to do something like this:
button.text = “Some text”
This will give a compiler error if you try something like that. I would make sense to be able to do it like that. Like in Visual Studio you can change text like that.

I’ll show you two methods on how you can change your UIButton text programatically.

Swift Change UIButton text – Method 1 (IBOutlet)

In the first method we will use an IBOutlet to change the button text. First create a UIButton somewhere on the storyboard. Second create the IBOutlet the normal way. Call the IBOutlet “button”. And you should end up with something like this:

@IBOutlet weak var button: UIButton!

Now in the viewDidLoad function we will try to set a new title for the button. Try put in this into the viewDidLoad function:
button.setTitle(“Ready”, forState: .Normal)

If you try to run your code in the simulator now, your app will start up with the button called Ready. The text from the storyboard should never even appear in your app. I have pasted the complete source code from the example below.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var button: UIButton!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

button.setTitle(“Ready”, forState: .Normal)

}

}

Swift Change UIButton text – Method 2 (IBAction)

Some might tell you that you can not change the UIButton text without an IBOutlet. In some cases it might be more practical to use an IBOutlet, if your button should change text without any user interaction. If you want the text to change after the user clicked the button, the IBOutlet is not needed. You can do that from the IBAction directly. Here is how.

In your example create an IBAction for your UIButton. Notice the first word in the parenthesis. It says sender, or at least it should say. That sender represent the UIButton. And you can use the same setTitle function directly with the sender. Check out this example.

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

}

@IBAction func buttonClicked(sender: AnyObject) {

sender.setTitle(“Sender”, forState: .Normal)

}

}

Try to run that example an see what happens. As soon you click the button, the text will change to “Sender”.

That is how you in Swift change UIButton text.

Check out UIButton in the swift documentation here https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/

See how to do it on video

Happy texting!

Posted in Programming, Swift, Xcode Tagged with: , ,

swift play mp3
May 9th, 2016 by ronny

Swift play mp3 from your app

Swift play mp3 from your app with this small example. To make swift play mp3 files we need to start with importing AVFoundation. That is where the audio player is.

import AVFoundation

Next we will create a variable for our music player.

var player = AVAudioPlayer()

Then we create a function to initialise the music player, and prepare the song. If you are using it as a background music you can run the function from viewDidLoad.

This is what you need to set up the player.

func initAudio() {
let path = NSBundle.mainBundle().pathForResource("music", ofType: "mp3")!
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(string: path)!)
player.prepareToPlay()
player.numberOfLoops = -1
player.play()
} catch let err as NSError {
print(err.debugDescription)
}
}

If you plan to start the music programmatically or from a button you will need to remove the player.play() line. Thats all the code you need to load and play a mp3 file.

Lets do an example with starting and stopping the music from a button. I assume you have created both and Action and IBOutlet for the button. Even though the IBoutlet can be skipped and solved in a different way.

The IBOutlet is called button. I’m not going thru how to create an IBOutlet here now. The following code will create a function you can call from your IBAction.

func playPause() {
if player.playing {
player.pause()
button.setTitle("Play music", forState: UIControlState.Normal)
} else {
player.play()
button.setTitle("Pause music", forState: UIControlState.Normal)
}
}

Now as I mentioned you can skip the IBOutlet if the only purpose is to change the button text. If you other things to the button you might need it. If not here is how you can skip that. First we need to take the code above (the code inside the playPause function) and paste it into the IBAction function. Then we change the button.setTitle(“Play music”, forState: UIControlState.Normal), to sender.setTitle(“Play music”, forState: UIControlState.Normal). Sender will be the same as button. Here is the complete code for the IBAction.

@IBAction func btnPlayMusic(sender: AnyObject) {
if player.playing {
player.pause()
sender.setTitle("Play music", forState: UIControlState.Normal)
} else {
player.play()
sender.setTitle("Pause music", forState: UIControlState.Normal)
}
}

To download a working example, please go to my github account here: https://github.com/solron/Swift-Play-Mp3

You will need to add your own mp3 file to that project. Mine was called music.mp3

Thats it for swift play mp3.

Happy playing!

Posted in Swift, Xcode Tagged with: , ,

swift send email
May 7th, 2016 by ronny

Swift send email from your iOS app

Swift send email from your iOS app. How do we do that…
It was easier than I first thought. At least with this method. Using the MessageUI and have the app to pre-fill an email and using iOS mail to send it.

First we need to import the MessageUI. We will do that from the view controller in my example code. By the way you can download the example code from my github. Just go to https://github.com/solron/Swift-Send-Email and download the code.

The we will need to setup the MFMailComposeViewControllerDelegate.

// Set delegate
class MyViewController: UIViewController,MFMailComposeViewControllerDelegate {
// Code goes here
}

My swift send email example only contains a send button on the user interface. Not showing here how to link an action to a button. But inside the button action code we do something like this:

@IBAction func btnSendEmail(sender: AnyObject) {
let email = MFMailComposeViewController()
email.mailComposeDelegate = self
email.setSubject("Subject goes here")
email.setMessageBody("Some example text", isHTML: false)
email.setToRecipients(["post@email.com"]) // the recipient email address
if MFMailComposeViewController.canSendMail() {
presentViewController(email, animated: true, completion: nil)
}
}

The code above will populate all fields needed to send you email. Subject field, recipient address and message body. You can of course edit any of these in the email that pops up before you send it. Because you will need to confirm the mail. Just like any other email you send. Just that you dont have to enter the information your self. The fields doesn’t have to be fixed in your code either. You can have dynamic values changed programatically based on anything you want.

Last we will need to enter the function in order for the delegate to work. And that is something like this:
func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
dismissViewControllerAnimated(true, completion: nil)
}

Now you have all the code you need to send emails from your app.

Thats it for swift send email.

Happy emailing!

Posted in Swift, Xcode Tagged with: , ,

change font size in xcode
April 23rd, 2016 by ronny

Change font size in Xcode dynamically

A short description on how to change font size dynamically. Without having to enter Xcode settings and change font size there. With this little Xcode plugin you can alter font size dynamically. I did not make this plugin, and is not affiliated with the creator in any way.

There can be lots of reasons why you want to change font size dynamically. For me its about the convenience.

First you need to download the plugin. Got to this github link: https://github.com/zats/AdjustFontSize-Xcode-Plugin

Download the zip file (Click Download Zip in upper right corner of the file list), and extract it.

Second you “right click” (tap with two fingers on a macbook of any kind) and select “Open with -> Xcode”.

Third you run the program by clicking the run/play button.

Thats it. You have now installed the plugin.

To use the new plugin to increase or decrease the fonts there are only two key combinations.

CMD and + to increase the font.
CMD and – to decrease the font.

Your Xcode is now setup to increase and decrease font size without entering Xcode preferences.

Happy changes!

Posted in Xcode Tagged with: ,

Xcode 7 iOS icon sizes
January 20th, 2016 by ronny

Xcode 7 iOS icon sizes overview

If you are looking for the Xcode 8 iOS icon sizes overview, please click the link there.

Xcode 7 iOS icon sizes overview. Since there quite a few iOS devices, it can be an extra challenging with all those different resolutions. Current Xcode (version 7), supports all iPhones since 4s, iPods and most iPads. You will need several different icons sizes. Thats what I will present here. A complete list of all different sizes for the different icons needed for an iOS application.

iOS icon sizes overview – 13 icons

iOS icon sizes

Just remember….

If you look at the picture above, you will see something like 29pt under the iPhone spotlight icon. First time I believed that was the icons size. And it is. But not i pixels. Above you see two empty icon windows saying 2x and 3x. That means 29 x 2 for the first window (58×58 pixels) and 29 x 3 for the second icon (87×87 pixels). Just multiply the pt value with x value, and you have the size in pixels. I usually create the largest icon (1024×1024), and uses photoshop (or any other image editing software) to make the smaller resolutions out of the biggest one.

Anyway, below you will find the list for the latest Xcode from when this article was written.

Icon Size list

Xcode 7 iOS icon sizes

iPhone spotlight iOS 5-9
29pt – 2x – 58×58
29pt – 3x – 87×87

iPhone spotlight iOS 7-9
40pt – 2x – 80×80
40pt – 3x – 120×120

iPhone App iOS 7-9
60pt – 2x – 120×120
60pt – 3x – 180×180

iPad settings iOS 5-9
29pt – 1x – 29×29
29pt – 2x – 58×58

iPad spotlight iOS 7-9
40pt – 1x – 40×40
40pt – 2x – 80×80

iPad App iOS 7-9
76pt – 1x – 76×76
76pt – 2x – 152×152

iPad pro App iOS 9
83,5pt – 2x – 167×167

iTunes Connect
App Icon – 1024×1024

Thats it about iOS icon sizes.

To read more about the subject, check out Apples Xcode documentation.
Or maybe check out my youtube channel.

Happy iconising!

Posted in Mac, Programming, Xcode Tagged with: , ,

Optimization WordPress Plugins & Solutions by W3 EDGE