Sunday, November 16, 2014

Activity Indicator Tutorial (Storyboard)

Activity Indicator Tutorial (Storyboard)

Step 1 -
               Add 2 buttons to the main view and Give them a title of start and stop.
Step 2 -
              Add Activity Indicator to the center of the view.
              Select the Activity Indicator and go to the Attributes Inspector.
              Give the Activity Indicator a style of Large
              White and a color if yellow. select the "Hides when stopped" option.
Step 3 -
              Create Outlet in ViewController.m. and  IBAction Method

           ViewController.m

      @interface ViewController ()

      @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;

      - (IBAction)startSpinning:(UIButton *)sender;
      - (IBAction)stopSpinning:(UIButton *)sender;

     @end
 
 
   Implementing created method
 
     - (IBAction)startSpinning:(UIButton *)sender {
          [self.activityIndicatorView startAnimating];
     }

     - (IBAction)stopSpinning:(UIButton *)sender {
      [self.activityIndicatorView stopAnimating];
   } 

Monday, November 10, 2014

Image Loading and Caching

Image Loading and Caching


var imageCache = [String : UIImage]()


var image = self.imageCache[urlString]
       
       
        if( image == nil ) {
            // If the image does not exist, we need to download it
            var imgURL: NSURL = NSURL(string: urlString)
           
            // Download an NSData representation of the image at the URL
            let request: NSURLRequest = NSURLRequest(URL: imgURL)
            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
                if error == nil {
                    image = UIImage(data: data)
                   
                    // Store the image in to our cache
                    self.imageCache[urlString] = image
                    dispatch_async(dispatch_get_main_queue(), {
                        if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
                            cellToUpdate.imageView?.image = image
                        }
                    })
                }
                else {
                    println("Error: \(error.localizedDescription)")
                }
            })
           
        }
        else {
            dispatch_async(dispatch_get_main_queue(), {
                if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
                    cellToUpdate.imageView?.image = image
                }
            })
        }



NOTE:This is in swift programming.

Tuesday, November 4, 2014

Toast message in iOS

Toast message in iOS

UIAlertView *toast = [[UIAlertView alloc] initWithTitle:nil message:@"Alert Example like toast" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
            [toast show];
            float duration = 0.5; // duration in seconds
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                [toast dismissWithClickedButtonIndex:0 animated:YES];

Monday, October 13, 2014

detecting iOS, iPhone, iPad and apple watch

detecting iOS, iPhone, iPad and apple watch

// detecting iOS


NSString *version = [[UIDevice currentDevice] systemVersion];
NSLog(@"Version:%@",version);

//detecting iPhone



add these line to your .h file

#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6_PLUS (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)


and use it in your .m file

if (IS_IPHONE_4)
        NSLog(@"iPhone 4");
else if (IS_IPHONE_5)
        NSLog(@"iPhone 5");

//detecting iPad


if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad)
{
        //code for iPad
}

//detecting apple watch

add these line to your .h file

#define IS_WATCH_42 (fabs((double)self.contentFrame.size.height - (double)174) < DBL_EPSILON)

#define IS_WATCH_38 (fabs((double)self.contentFrame.size.height - (double)151) < DBL_EPSILON)


and use it in your .m file

if (IS_WATCH_42)
        NSLog(@"apple watch 42mm");
    else if (IS_WATCH_38)
        NSLog(@"apple watch 38mm");

Friday, October 10, 2014

Simple Animation

Simple Animation

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//your code
[UIView commitAnimations];

Friday, October 3, 2014