Thursday 29 January 2015

Siri lables animation in ios

In viewDidload ..... 

   NSArray *labeltexttoanimate = @[@"Awesome",@"Animation",@"Like...",@"Siri......"];
    
    [self animateLabels: labeltexttoanimate];

- (void)animateLabels:(NSArray *)labels
{
   
    NSLog(@"the data in the labels is %@",labels);

    CGFloat firstLabelStartTop = 600;
    
    [labels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)

{
       
CGFloat delay = 0.15 * idx;

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(150, firstLabelStartTop + 30 * idx, 320, 21)];

        label.text = obj;

        label.alpha = 0.0;

        [self.view addSubview:label];
        
        [UIView animateKeyframesWithDuration:2.4
                                       delay:delay
                                     options:0
                                  animations:^{
                                      [UIView addKeyframeWithRelativeStartTime:0.0
                                                              relativeDuration:0.2
                                                                    animations:^{
                                                                        label.alpha = 1.0;
                                                                        label.frame = CGRectOffset(label.frame, 0, -400);
                                                                    }];

                                      [UIView addKeyframeWithRelativeStartTime:0.2
                                                              relativeDuration:2.0
                                                                    animations:^{
                                                                        label.frame = CGRectOffset(label.frame, 0, -200);
                                                                    }];
                                      
                                      [UIView addKeyframeWithRelativeStartTime:0.5
                                                              relativeDuration:0.2
                                                                    animations:^{
                                                                        label.alpha = 0.0;
                                                                        label.frame = CGRectOffset(label.frame, 0, -200);
                                                                    }];
                                  }
                                  completion:^(BOOL finished)
                                 {
                                   
                                  }];
    }];
    

}

Monday 16 December 2013

Sharing Your message in Social Websites like Facebook, Twitter, GooglePlus, LinkedIn


Sharing your text in Facebook....


1. Import the SocialFramework in your project and #import<Social/Social.h> in your ViewController.
2. In the button action write the below code.

   SLComposeViewController *send = [SLComposeViewController  composeViewControllerForServiceType:SLServiceTypeFacebook];
  [send setInitialText:@"Say some thing "];
  [self presentViewController:send animated:YES completion:nil];

Sharing your text in Twitter....


1. Import the SocialFramework in your project and #import<Social/Social.h> in your ViewController.
2. In the button action write the below code.

   SLComposeViewController *send = [SLComposeViewController  composeViewControllerForServiceType:SLServiceTypeTwitter];
  [send setInitialText:@"Say some thing "];
  [self presentViewController:send animated:YES completion:nil];


Sharing your text in GooglePlus....

1. In the button action write the below code.

NSString *post =[NSString stringWithFormat:@"http://plus.google.com/share?url=yoururl"];
NSLog(@"s is %@",post);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:post]];


Sharing your text in LinkedIn....


1. Add this folder to your project .
2. If you are using Arc in your project then go to project settings and go to BuildPhases and add "-fno-objc-arc" to the particular class.
3.For example  See this link
4. Go to LinkedIn Developer website and create your own API key and Secret .
5. Provide your API key and secret  in MISLinkedinShare.h.
6. In your view controller #import "MISLinkedinShare.h"
7. In your button action write the below code.

[[MISLinkedinShare sharedInstance] shareContent:self postTitle:@"your title" postDescription:@"your Description" postURL:@"your url" postImageURL:@"your image url"];








Thursday 10 October 2013

Lazy image loading in ios 


  1. Add AFNetworking and UIKit+AFNetworking using the  Github link .
  2. Add these two files to your project and where ever your image is loading #import
    "UIImageView+AFNetworking.h".
  3. [cell.yourimageview setImageWithURL:[NSURL URLWithString:@"your image url"] placeholderImage:[UIImage imageNamed:@"your place holder image"]];
  4. Add Security and SystemConfigaration Framework.

Wednesday 18 September 2013

Remove HTML Tags from an NSString on the iPhone

UITextView *textview= [[UITextView alloc]initWithFrame:CGRectMake(10, 130, 250, 170)];
NSString *str = @"This is <font color='red'>simple</font>";
[textview setValue:str forKey:@"contentToHTMLString"];
textview.textAlignment = NSTextAlignmentLeft;
textview.editable = NO;
textview.font = [UIFont fontWithName:@"vardana" size:20.0];
[UIView addSubview:textview];

Saturday 10 August 2013

Getting the Twitter tweets according to the screen name in iPhone using Twitter 1.1 api

Twitter tweets according to the screen name in iPhone using Twitter 1.1 api

Download source code here   Make sure that i am using arc in this project



1. Login with your twitter credentials https://dev.twitter.com/  through this link .
2. Now on the top right corner your profile pic is there and click on that and go to my applications and create a new application.
3. Create a new application 
4.Fill the fields and ignore the call back url
5. Here you get the consumer key and the consumer secret.
 6.Create your own access token
here you can get your own access token
7.Concatenate the consumer key , a colon character ":", and the consumer secret in to a single string.

example 

Consumer Key       xvz1evFS4wEEPTGEFPHBog

Consumer Secret    L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg

Concatenate these two  xvz1evFS4wEEPTGEFPHBog:L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg

8.Now the concatenate string is to be encoded with the base 64 using the below link,

http://www.motobit.com/util/base64-decoder-encoder.asp

convert the source data.

At last the encoded base 64 string is eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==  

9.Now open your xcode and create an new project and in  this method

create propertys and synthesize these parameters

 NSMutableData *responseData;

 NSString *acesToken;

 NSString *compareString;

 NSArray *tweetsArray;

 NSDictionary *tweetsDictionary;

IBOutlet UIImageView *imag;

 -(void)viewdidload
{
compareString =@"accestoken";

NSString* encodeingStr = @"eHZ6MWV2RlM0d0VFUFRHRUZQSEJvZzpMOHFxOVBaeVJnNmllS0dFS2hab2xHQzB2SldMdzhpRUo4OERSZHlPZw==";

NSData* data = [encodeingStr dataUsingEncoding:NSUTF8StringEncoding];

NSString *serverURL = @"https://api.twitter.com/oauth2/token";

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:           [NSURL  URLWithString:serverURL]];

[request setHTTPMethod:@"POST"];

[request setHTTPBody:data];


[request addValue:[NSString stringWithFormat:@"Basic %@",encodeingStr] forHTTPHeaderField:@"Authorization"];

[request addValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

NSString *post =@"grant_type=client_credentials";

[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

 [conn start];

}

this is how we are requesting the twitter api 1.1.

Now the delegate methods will fire,

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    responseData = [[NSMutableData alloc]init];
    
    [responseData setLength:0];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    
    NSString *status = [[NSString alloc] initWithData:responseData
                                             encoding:NSUTF8StringEncoding];
    
    
  tweetsDictionary = [self dictionaryFromJSONData:[status dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    if ([comparestring isEqualToString:@"accestoken"])
    {
        acestoken = [tweetsDictionary objectForKey:@"access_token"];
        
        NSLog(@"the data in the accesstoken is %@",acestoken);
         
        [self postingfortweetes];

    }
    else if ([comparestring isEqualToString:@"gettingtweets"])
    {
        self.twittertable.dataSource = self;

        NSLog(@"the data in the status is %@",status);
       
        [twittertable reloadData];
        
        NSArray *arr = [[tweetsDictionary valueForKey:@"user"]objectAtIndex:0];

        NSLog(@"the data in the user is%@",arr);

        NSString *str = [arr valueForKey:@"profile_image_url_https"];

        NSLog(@"the data in the url is %@",str);

        NSURL *url = [NSURL URLWithString:str];

        NSLog(@"the url is %@",url);

        NSData *data = [NSData dataWithContentsOfURL:url];

        imag.image = [UIImage imageWithData:data];
       
      }
    
    
}

-(void)postingfortweetes
{
    
    comparestring = @"gettingtweets";

    NSString *serverURL =[NSString stringWithFormat:@"https://api.twitter.com//1.1/statuses/user_timeline.json?count=100&screen_name=%@",twitterid];
   //here in the place of twitter id give your twitter id
   
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]];

 [request setHTTPMethod:@"GET"];

[request addValue:[NSString stringWithFormat:@"Bearer %@",acestokenforHTTPHeaderField:@"Authorization"];
    
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    
 [conn start];
    
    
}


- (NSDictionary *)dictionaryFromJSONData:(NSData *)data
{
    NSError *error;
    NSDictionary *dictionaryParsed = [NSJSONSerialization JSONObjectWithData:data
                                                                     options:0
                                                                       error:&error];
    if (!dictionaryParsed)
    {
        if (error)
        {
            //#warning Handle the error here.
            NSLog(@"error");
        }
        return nil;
    }
    return dictionaryParsed;
}

Now the total tweets are in tweetsDictionary, now these tweets to the uitableview.


Drag and drop your UITableview in your xib file and connect delegate method and the data source method .


// uitableview delegate methods


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[tweetsDictionary valueForKey:@"text"] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)

    {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    cell.textLabel.text = [tweetsDictionary valueForKey:@"text"][indexPath.row];

    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath  *)indexPath
{
   return 90;
}

sorry for my bad english, i hope this tutorial will help you .