Generating UIButton Programmatically

uibuttonWhen you are working on an iOS app, you invariably end up creating buttons on your view controllers. For some of the apps, you know exactly where everything goes and you place everything beforehand in your storyboard file. But if your app is more complex, you may want to create the buttons dynamically. This means is that creating a button might be interactive and can depend on the actions of the user. How do we create buttons programmatically? Once they are created, how do we associate actions with them?   Continue reading

Plus vs Minus In Objective-C

plus-minus-balance 3d MännchenWhenever you are working with an iOS app, you would have seen those functions and how they have a plus or a minus sign at the beginning. Ever wondered what they are? Objective-C requires that the interface and implementation of a class be in separate code blocks. That’s the reason you will see a .h and a .m file as a pair. Interface is the same as class definition in other languages. By convention, we place the interface in a header file and the implementation in a code file. In the header file, we declare functions with these ‘+’ and ‘-‘ signs. Do they make any real difference or do we have them just as part of the Objective-C language protocol? Well, they exist for a reason and there is a real difference between the signs.   Continue reading

How To Trigger A Segue Programmatically In iOS

mainYou have your storyboard ready and you have created the necessary segues. Great! Now how do we trigger these segues programmatically? There are many different ways to do it. One of the nicer ways to do this is by connecting two scenes in a storyboard using a segue that is not attached to an action. After that, you can programmatically trigger the segue inside your view controller. The way you do this is by control-dragging from the file owner icon at the bottom of the storyboard scene to the destination scene.   Continue reading

Dismissing The UITextField Keyboard

ios-keyboardLet’s say you are designing an iOS application which takes user input using a text field. When you add a text field to your storyboard and run your application, you will see that when you tap on the text field, the keyboard pops up automatically. But when you tap the return key, they keyboard doesn’t go away. As it turns out, the popping up of the keyboard is taken care of when you add the UITextField, but dismissing the keyboard is up to you. Here’s how you make it go away after you are done taking the input from the user:   Continue reading

iOS App: Separator Lines And Back Button In Master-Detail Application

mainWhen you create a master-detail application in iOS, a few things appear by default. If you notice it, you will see that the empty cells are separated by lines. But we want the separator lines to appear for items that are there in the table. Also, you will notice that the back button in the detail view contains the title by default. What if we want it to say something else? Perhaps not say anything at all. How do we do it?   Continue reading

How To Load Different XIBs Based On The Device Type?

mainWhat’s with all the different sizes of the iOS devices? I mean, sure we have autolayout feature that takes care of things in general. But if you want real aesthetic perfection, then you are better off having a separate XIB for each screen size. If you create a universal app, Xcode automatically creates two separate XIBs for iPhone and iPad. But if you want to differentiate between the 3.5 inch screen and the 4 inch screen on the iPhone, you should create a new XIB and add it to your project. You should of course name them accordingly. You can then load the XIBs by checking for the device type as given below.   Continue reading

Transition Effects In iOS Apps

One of the more visually appealing aspects of iOS development is the crisp transition effect. Whenever you see a beautiful iOS app, it has all the elements interacting with each other seamlessly with gorgeous transitions and other visually appealing effects. If you have tried your hand at building one of these apps, you must have noticed that there are a couple of default options available, like flip or curl. But how do we go past this? How do we build all the fancy transition effects into our app? There are actually two different approaches you can follow.   Continue reading