Thursday, May 29, 2014

Simple way to Share Images from iOS App to Facebook and Twitter - One method for both

sharing Image in social sites (Facebook and Twitter)....first import social,facebook,twitter frameworks


/To share the final image on twitter
-(void)shareImageToTwitter
{
    [self shareImage:savedImage withText:nil onSocialSite:SLServiceTypeTwitter];
}

//To share the final image on facebook
- (void)shareImageToFacebook
{
    [self shareImage:savedImage withText:nil onSocialSite:SLServiceTypeFacebook];
}

here "savedImage " was sharing image


//Common method to share image on twitter & facebook
-(void)shareImage :(UIImage *)postImage withText :(NSString *)message onSocialSite :(NSString *const )socialSiteType
{
    SLComposeViewController *socialSiteComposer=[SLComposeViewController composeViewControllerForServiceType:socialSiteType];
    if([SLComposeViewController isAvailableForServiceType:socialSiteType])
    {
        SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
           
            [socialSiteComposer dismissViewControllerAnimated:YES completion:nil];
           
            switch(result)
            {
                case SLComposeViewControllerResultCancelled:
                default:
                {
                    NSLog(@"Cancelled.....");
                }
                    break;
                case SLComposeViewControllerResultDone:
                {
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Posted successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alertView show];
                }
                    break;
            }};

        //Add content to post
        [socialSiteComposer setInitialText: message];
        NSData *data = UIImageJPEGRepresentation(postImage, 1.0);
        [socialSiteComposer addImage:[UIImage imageWithData:data]];
       
        [socialSiteComposer setCompletionHandler:completionHandler];
        [self presentViewController:socialSiteComposer animated:YES completion:nil];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"You can't post right now, make sure you have at least one account setup" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

Monday, February 24, 2014

How to set Header View of UItableview To stick at the top in iOS

//To stick the header to the Table view
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat sectionHeaderHeight = 50;
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
    {
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight)
    {
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }

}

Friday, January 24, 2014

How to set Navigation Bar font style and font through out application in iOS


    in App delegate


    [[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      
      [UIColor blueColor], UITextAttributeTextColor,
      
       [UIColor greenColor], UITextAttributeTextShadowColor,
      
      [NSValue valueWithUIOffset:UIOffsetMake(-3, 3)], UITextAttributeTextShadowOffset,
      
      [UIFont fontWithName:@"Futura-CondensedMedium" size:20.0], UITextAttributeFont,
      

      nil]];

Navigation Bar Bagground image

  UINavigationBar *navBar =[[self navigationController] navigationBar];

     [navBar setBackgroundImage:[UIImage imageNamed:@"topbar_bg.png"forBarMetrics:UIBarMetricsDefault];

Thursday, January 9, 2014

How to Customize UIActionSheet buttons in iOS

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet  // before animation and showing view
{
    //To Grayed out Cancel button if there is no loaded image
    for (UIView* view in [actionSheet subviews])
    {
        if ([[[view class] description] isEqualToString:@"UIAlertButton"])
        {
            if ([view respondsToSelector:@selector(title)])
            {
                NSString* title = [view performSelector:@selector(title)];
                
                if ([title isEqualToString:@"Cancel"] && [view respondsToSelector:@selector(setEnabled:)])
                {
                    if(imageView.image == nil)
                    {
                        view.backgroundColor = [UIColor grayColor];
                        view.alpha = 0.5;
                    }
                }
            }
        }
    }

}

http://stackoverflow.com/questions/743636/iphone-disabling-uiactionsheet-buttons