A few components every iOS developer should know

A few components every iOS developer should know

Being a developer we all like to write code to create things that perform just the way we like. This can be very time consuming, especially when that what you are looking for is not standard available in iOS and you have to write it yourself. In several cases we are trying to rebuild something that we liked and seen before. In this blog you will discover a few components that can make your life easier. Using them will not only save you time but will also keep you from reinventing the wheel.


The first component, named SVProgressHUD, is widely known and frequently used. Perfect if your application needs a loading display.
You can find it here: https://github.com/samvermette/SVProgressHUD
Setting it up is really easy:

1. Drag the SVProgressHUD/SVProgressHUD folder into your project.
2. Add the QuartzCore framework to your project.
3. SVProgressHUD is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call [SVProgressHUD method]).
4. To show the hud call:

+ (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;

The string is the title the hud must have and by giving it a maskType you can choose whether the background should get darker. Note: Setting a maskType also prevents underlying views from capturing touches. SVProgressHUD can also reflect the progress of a task:

+ (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;

You don’t need to give a status or maskType, but it can be usefull in some cases.

An alternative for SVProgressHUD is MBProgressHUD.


ISRefreshControl makes it easy to implement a refreshcontrol that will work nicely both on iOS5 and iOS6. On iOS6 it uses the natively available UIRefreshControl. If you’re running iOS5 it uses a custom implementation. ISRefreshControl sends UIControlEventValueChanged events when the content offset of its UITableView exceeds a threshold. UITableViewController is extended to send content offset to ISRefreshControl.
You can find it here: https://github.com/ishkawa/ISRefreshControl
How to set it up:

1. Add files under ISRefreshControl/ to your project.
2. Import ISRefreshControl.h.
3. Put this in the viewDidLoad.
self.refreshControl = (id)[[ISRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refresh)

or just call addSubview:
UIScrollView *scrollView = [[UIScrollView alloc] init];
ISRefreshControl *refreshControl = [[ISRefreshControl alloc] init];
[scrollView addSubview:refreshControl];
[refreshControl addTarget:self action:@selector(refresh)

Note: Currently, ISRefreshControl cannot be set up with storyboards.


User experience is everything on iOS that’s why we always want our apps to work as easy as possible.
HTAutocompleteTextField makes our lives easier by automatically suggesting the domain as a user types an email address. Use this component in your apps whenever you can, particularly for email addresses and your users will appreciate it!
You can find it here: https://github.com/hoteltonight/HTAutocompleteTextField

This is how it’s done:
1. Add these files to your project: HTAutocompleteTextField.m, HTAutocompleteTextField.h
HTAutocompleteManager.m and HTAutocompleteManager.h

2. Create an HTAutocompleteTextField instance exactly like a normal UITextField. You can do it either programmitcally or in Interface Builder. Programmatically, this looks like:

HTAutocompleteTextField *textField = [[HTAutocompleteTextField alloc] initWithFrame:CGRectMake(0,0,100,31)];

3. The datasource is the brain of the autocomplete logic. If you just want to autocomplete email addresses, use HTAutocompleteManager from the example project as follows:
textField.autocompleteDataSource = [HTAutocompleteManager sharedManager];
textField.autocompleteType = HTAutocompleteTypeEmail;

It’s also possible to use custom autocompletion according to your needs. You can create your own datasource implementation for the textfield. To do this you have to implement this method:

- (NSString *)textField:(HTAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix

If you like you can even change the default datasource for all HTAutocompleteTextFields:

[autocompleteTextOffset setDefaultAutocompleteDataSource:[HTAutocompleteManager sharedManager]];

To adjust the properties (i.e. font, textColor) of the autocomplete label, do so via the `[AutocompleteTextField autocompleteLabel] property.
textField.autocompleteLabel.textColor = [UIColor grayColor];

Other things to look at

These are only 3 of the wide range of components you can use in your application. If you’re about to build a custom component, it’s a good idea to take a look at Cocoa Controls first. (http://www.cocoacontrols.com).
You will find many components there that will probably contain 90% of the functionality you are looking for.

Other great components to look at are: KSLabel, iCarousel, ResizeImage,...

Last but not least, another good tip for developers is using “KSImageNamed”. This macro will autocomplete your “imageNamed” calls in Xcode like you'd expect. Just type in [NSImage imageNamed: or [UIImage imageNamed: and all the images in your project will conveniently appear in the autocomplete menu. You can find it here: https://github.com/ksuther/KSImageNamed-Xcode

Thanks for reading.

Happy coding!
Birgit Van Keer.