objective-c Archive

TUTORIAL: Creating custom layouts for UICollectionView

In the previous part of this tutorial, basic usage of UICollectionViewFlowLayout was discussed.  UICollectionViewFlowLayout is a powerful and convenient way to create beautiful collections, but sometimes a more sophisticated approach is needed. This tutorial will show, how

A Quick tip: Adding and removing NSNotificationCenter observers in UIView subclass

It is sometimes needed for a UIView subclass to register as an NSNotificationCenter observer. However, there seems to be no good place for adding/removing NSNotificationCenter observers… The best place, I have found so far, is in willMoveToWindow: and didMoveToWindow

How to detect a jailbroken device programmatically?

Why is it necessary to detect a jailbroken device? Sometimes it’s necessary to restrict iOS app to run only on non-jailbroken devices. For example, it might be useful for media applications to make content piracy more difficult

How to use NSLog and print only for debugging?

Why NSLog and print are dangerous? Using NSLog and print are very popular logging mechanisms in iOS applications. However, in most cases logging to standard output is useful only for debugging applications and is useless in the released application.

UIPageViewController: how to get current page index and current visible controller?

UIPageViewController has the viewControllers array property. The currently visible viewController is always the first one in the viewControllers array. Example: Objective-C: Swift: The easiest way to get the current index is to have the itemIndex property in every content controller and just retrieve its

iOS TUTORIAL: Creating a custom tabbar using Storyboard in Xcode

Custom tabbar Custom tabbar is a quite common task for an iOS developer. It’s normal –  the look and feel of the standard tabbar in iOS 7+ is quite good, but it doesn’t suite always into the app’s

Using the Objective-C runtime and method swizzling

Objective-C runtime is often an unknown topic for new iPhone developers. In practice, using Objective-C Runtime is needed really seldom, but there are situations, when its usage saves a lot of work and makes things easier. One of

TUTORIAL: Creating an iOS App Extension to perform custom actions with Safari content

iOS App Extension From all the new features introduced in iOS 8, app extensions are definitely the most exciting ones, especially Action Extensions as they “help users view or transform content within the context of another app”

iOS Orientations: Landscape orientation for only one View Controller

Updated for iOS 9.3 in June 2016. In an iOS app, there can often be situations, when it’s necessary to support landscape orientation for only one view controller. All other views should be in portrait. A movie player or a gallery are nice

TUTORIAL: Draw a nice triangle view with a border using CAShapeLayer

Drawing a custom-shaped background view with a CAShapeLayer is an easy way, how to decorate the app and make its titles or headers more distinguished. The demo app The demo app for this tutorial contains only one view with a background image, a