Swift

To Design Custom Icon for IOS App

Hey Guys! In android, we developers are really lucky to copy/paste the icons to our app. In IOS However, Apple makes you add very specific sizes. We need different sizes, because devices are different. Ipad, different versions of Iphone… They all display different resolution of icons. Of course, newer models have high resolutions. But we have to think all devices.:)

Sooo, Lets Begin!

When we take a look at image.xassests for our AppIcon there will be Iphone — Iphone Spotlight — Iphone App and so on… The important thing is below this pictures there is “pt”(points). Also, there will be 2x or 3x or whatever for each different size. So All we gotta do is to multiply points with this sizes. For example, In the first picture there is an iphone with 29 pt and 2x size so we must have icon with (29 x 2 = 58) 58 pxs. For other devices you should also have 58pxs, 80pxs, 87pxs, 120pxs, 180pxs…
Also, As you might noticed all icons should be SQUARE. But you can change the image with insets to rectangle or whatever you want.:)

Swift

How to limit number of characters for your textfield?

Hey! Limiting number of characters is really easy if you have standard keyboard. The link below offers so many options for this prob:
http://stackoverflow.com/questions/7010547/uitextfield-text-change-event

But these options werent fit for me. In my case, I had custom keyboard…
The solution I found was pretty satisfying.
I wrote a function to check max length of a text field. Then I checked this func every time I added character to my textfield.

  @IBAction func addBtnLabel(sender: AnyObject) {
         txtFieldPlateNumber.text =  txtFieldPlateNumber.text?.stringByAppendingString(sender.titleLabel!!.text!)        checkMaxLength(txtFieldPlateNumber as! UITextField, maxLength: 14)
     }

    func checkMaxLength(textField: UITextField!, maxLength: Int) {
         if (textField.text?.utf16.count > maxLength) {
             deleteLastCharacter()
         }
     }

//To delete backwards.
 func deleteLastCharacter(){

        if (txtFieldPlateNumber == 0) {
             // textField is empty
             print("text field is empty")
         }
         else{
             var name: String = txtFieldPlateNumber.text!
             var truncated = String(name.characters.dropLast())                       txtFieldPlateNumber.text = truncated
        }
     }

   Thinking simple, creates simple solutions. 🙂