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

How to COMBINE / MERGE two images into ONE image in iOS



// combine/ merge two images into one image

- (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage
{
    UIImage *image = nil;
    
    CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height));
    if (UIGraphicsBeginImageContextWithOptions != NULL) {
        UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
    } else {
        UIGraphicsBeginImageContext(newImageSize);
    }
    [firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2),
                                        roundf((newImageSize.height-firstImage.size.height)/2))];
    [secondImage drawAtPoint:CGPointMake(roundf((newImageSize.width-secondImage.size.width)/2),
                                         roundf((newImageSize.height-secondImage.size.height)/2))];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;

}