Wednesday, January 22, 2014

iOS - Icons

Web Hosting


Use of Icons

It is an image representation used for an action or depicts something related to the application.

Different icons in iOS

  • AppIcon
  • App icon for the App Store
  • Small icon for Spotlight search results and Settings
  • Toolbar and navigation bar icon
  • Tab bar icon

AppIcon

AppIcon is the icon for application that appears on the device springboard (the default screen that consists of all the applications.)

App icon for the App Store

It is a high resolution image of app icon of size 512 x 512 or 1024 x 1024(recommended)

Small icon for Spotlight search results and Settings

This small icon is used in searched list of application. It is also used in the settings screen where the features related to the application are enabled and disabled. Enabling location services is one such example.

Toolbar and navigation bar icon

There are list of standard icons that are specially made for use in the toolbar and navigation bar. It includes icons like share, camera, compose and so on.

Tab bar icon

There is a list of standard icons that are specially made for use in Tab bar. It includes icons like bookmarks, contacts, downloads and so on.
There are special guidelines for the size of each icon for different iOS devices. You can explore further on the icon guidelines in apple documentation on Human Interface Guidelines.


Web Hosting

iOS - Alerts

Web Hosting


Use of Alerts

Alerts are used to give important information to user. Only after selecting the option in the alert view we can proceed further using the app.

Important properties

  • alertViewStyle
  • cancelButtonIndex
  • delegate
  • message
  • numberOfButtons
  • title

Important methods

- (NSInteger)addButtonWithTitle:(NSString *)title
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
- (void)dismissWithClickedButtonIndex:
  (NSInteger)buttonIndex animated:(BOOL)animated
- (id)initWithTitle:(NSString *)title message:
  (NSString *)message delegate:(id)delegate
  cancelButtonTitle:(NSString *)cancelButtonTitle 
  otherButtonTitles:(NSString*)otherButtonTitles, ...
- (void)show

Update ViewController.h as follows

Make your class conform to alert view delegate protocol by adding < UIAlertViewDelegate> as shown below in ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIAlertViewDelegate>{
    
}
@end

Add custom method addAlertView

-(void)addAlertView{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Title" message:@"This is a test alert" delegate:self 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alertView show];
}

Implement alert view delegate method

#pragma mark - Alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
  (NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"Cancel button clicked");
            break;
        case 1:
            NSLog(@"OK button clicked");
            break;
        
        default:
            break;
    }
}

Update viewDidLoad in ViewController.m as follows

(void)viewDidLoad
{
   [super viewDidLoad];
   [self addAlertView];
}

Output

Now when we run the application we'll get the following output.
iOS Tutorial


Web Hosting

iOS - Sliders

Web Hosting


Use of Sliders

Sliders are used to choose a single value from a range of values.

Important properties

  • continuous
  • maximumValue
  • minimumValue
  • value

Important method

- (void)setValue:(float)value animated:(BOOL)animated 

Add custom methods addSlider and sliderChanged:

-(IBAction)sliderChanged:(id)sender{
    NSLog(@"SliderValue %f",mySlider.value);
}
-(void)addSlider{
    mySlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, 200, 23)];
    [self.view addSubview:mySlider];
    mySlider.minimumValue = 10.0;
    mySlider.maximumValue = 99.0;
    mySlider.continuous = NO;
    [mySlider addTarget:self action:@selector(sliderChanged:) 
    forControlEvents:UIControlEventValueChanged];
}

Update viewDidLoad in ViewController.m as follows

(void)viewDidLoad
{
   [super viewDidLoad];
   [self addSlider];
}

Output

Now when we run the application we'll get the following output.
iOS Tutorial
On dragging the slider the output will be as follows and will print the new value in the console.
iOS Tutorial


Web Hosting