Last updated by at .

iOS Programming Recipe 20: Using CAGradientLayer In A Custom View

This recipe will demonstrate how to use CAGradientLayer to add gradients to a custom UIView.

Assumptions

  • You should have basic knowledge of UIView and Core Animation, specifically CALayer.
  • Basic knowledge of autolayout usage in interface builder.

Getting Started

Setting Up A Sample Application
  • Create a new Single View Application in Xcode named GradientViewDemo. Make sure to check Use Automatic Reference Counting and uncheck Use Storyboards. Our demo app will also be iPhone only to keep things simple, but go ahead make a universal app if you like (everything we will do is applicable on both iPhone and iPad),
  • Create a new UIView subclass named NSCBGradientView. We added the NSCB class prefix, because this may be a valuable component to reuse in future projects and the prefix will help avoid name clashing.
  • Next, we need to add QuartzCore to the target. Do so by selecting the project file in the source list on the left, then ensure the GradientViewDemo target has been selected, select the Build Phases tab from the tab bar at the top, expand the Link Binary with Libraries, and finally click the + button in the lower left corner. Search for QuartzCore, and then add it to the target.

[Read more...]

iOS Programming Recipe 10: Adding A Shadow To UIView

Assumptions

Shadows!

Even the slightest drop shadow here and there can dramatically improve the look of your application’s UI, but at what cost?

Today we will cover adding shadows to UIViews of all kinds. Feel free to check out the source code for this recipe available on our GitHub page.

[Read more...]

iOS Programming Recipe 8: Using UIAppearance For A Custom Look

Everyone wants to make their app look unique! Well the UIAppearance protocol can help you! In iOS 5.0 Apple introduced the UIAppearance proxy API which allows you the developer to customize many of the appearance aspects of UIKit elements. I know what you’re thinking… Can’t I already do that? Well sure, but not on the same scale as UIAppearance will allow, and furthermore, changing the appearance of UI components on a per object basis gets really old, really fast.

So let’s dive into an example right quick…

Say you have an app with a UINavigationBar and you want something other than the default background color (tint color). You would probably try something similar to the following


[self.navigationBar setTintColor:myColor];

Then you decide another part of your app needs a navigation bar and you end up writing the same code to change the background color for that one as well. This continues as time goes on and before long you end up with an unmanageable mess, leaving you sad and depressed wishing there was a better way… enter UIAppearance…

[Read more...]

iOS Programming Recipe 6: Creating a custom UIView using a Nib

Creating a custom UIView using a Nib

Assumptions
  1. You are familiar with creating UIView subclasses, and instantiating UIView’s both from a Nib file or in code
  2. You are familiar with Nib files
Background

Sometimes you find yourself trying to create a quick composite UIView (UIView subclass w/ multiple subviews) where a UIViewController doesn’t seem necessary Please note that a UIViewController is the right choice most of the time. This can be a real pain to setup entirely in code if you have many subviews, and god forbid if you want to use auto layout! So you may find yourself wanting to use a nib to simplify things a bit, well this tutorial will go through the process of doing just that.

Getting Started
  • Create a new Xcode project based on the single view application template for iOS. This tutorial will assume you are using ARC, so you may want to make that selection when creating the new project.
  • Once you have created the new project a new UIView subclass to the project and name it CustomView.
  • Then create a new Nib file named CustomView.nib and add it to the project.
[Read more...]
css.php
Privacy Policy