Android, app, book, currency, designPatterns, doviz, dovizkur, doviztakip, ionic, kur, lifestyle, playstore, Swift, swift4, takip, Uncategorized, yazilim

Swift 4 Skeleton Project

Hey everyone!

Here is skeleton project for our swift projects with mvc, shared folders and some objective C libraries(for UI animations- ProgressHUD etc.)

This project is also base of angela yu’s project!

https://github.com/rozeridilar/Quizzler—London-App-Brewery

Enjoy!

Alsoo, here is common auto layout issues both programmatically and Main Board Solutions:

https://github.com/rozeridilar/AutoLayoutWorkSpace

https://github.com/rozeridilar/Dicee—AutoLayoutIssues

Advertisements
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. 🙂

Swift

Create Custom Keyboard Just For Your App!

I’m building an iOS app using a Storyboard. And I had to add custom keyboard for my own app. For designing keyboard I had soo many difficulties(Autolayout is an art, not a science.) But finally I fixed. Then I looked everywhere to use keyboard like a subview. (I did not want to add keyboard like target but just subview.) Soo, Here is what I ended up doing to accomplish everything. The only thing you need to consider in addition to this is to think a basic subview and remove classic keyboard from UItextField.

1- So, I added -Content View- to my View Controller in StoryBoard and I added all buttons that I need for my own keyboard. Then in my ViewController class, to make it add buttons  to UITextField I wrote:

@IBAction func addBtnLabel(sender: AnyObject) {
         txtFieldNumber.text =  txtFieldNumber.text?.stringByAppendingString(sender.titleLabel!!.text!
 }

Then for my delete button I wrote:

@IBAction func deleteBtnLabel(sender: AnyObject) {

        

        if (txtFieldNumber == 0) {

            // textField is empty

            print("text field is empty")

        }

        else{

            //txtFieldNumber.text =  txtFieldNumber.text?.

            var name: String = txtFieldNumber.text!

            var truncated = String(name.characters.dropLast())

            txtFieldNumber.text = truncated

        }

    }

Also do NOT forget the removing keyboard! I wrote some sort of trick to remove standard keyboard in viewDidLoad:

  keyboardToPost.backgroundColor = UIColor(red: 98/255 , green: 102/255 , blue: 102/255 , alpha: 1.0)        

        // initialize custom keyboard

        let keyboardView = Keyboard(frame: CGRect(x: 0, y: 0, width: 0, height: 0))

        txtFieldNumber.inputView = keyboardView

Thats what I ended up.
All files are in my github page with full version of it: https://github.com/rozeridilar/customKeyboard
If you have any questions, don’t hesitate to contact me!

Swift

Controlling App Fonts in Swift

Hi! After I added custom fonts to my Swift – IOS project, I had some problems to reach my custom fonts.All I did was to add .otf folders to under the resources folder in my project. Then I added them via info.plist under — Fonts provided by application–. But then somehow project did not recognize some of my .otf fonts. So I wanted to reach all fonts that I can use for my project. Then I added below function to my project in somewhere just to make it run:

 //   TO GET  FONT NAMES

        for family: String in UIFont.familyNames()

        {

            print("\(family)")

            for names: String in UIFont.fontNamesForFamilyName(family)

            {

                print("NAMES == \(names)")

            }

        }