Programmatically Show Call Out on Annotation


- (void)mapView:(MKMapView *)mymapView didAddAnnotationViews:(NSArray *)views
{
    //Show call out
    [mapView selectAnnotation:[[mapView annotations] lastObject] animated:YES];
}

Bring MKAnnotation to Front


- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    for (MKAnnotationView * annView in views) {
        MapAnnotation* mapAnnotation = (MapAnnotation *)[annView annotation];
        if([mapAnnotation.type isEqualToString:@"Call Out"])
        {
            [[annView superview] bringSubviewToFront:annView];
            break;
        }
    }
}

URL Encode


NSMutableString *escaped = [actionString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];      
[escaped replaceOccurrencesOfString:@"&" withString:@"%26" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"+" withString:@"%2B" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"," withString:@"%2C" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"/" withString:@"%2F" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@":" withString:@"%3A" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@";" withString:@"%3B" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"=" withString:@"%3D" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"?" withString:@"%3F" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"@" withString:@"%40" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@" " withString:@"%20" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"\t" withString:@"%09" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"#" withString:@"%23" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"<" withString:@"%3C" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@">" withString:@"%3E" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"\"" withString:@"%22" options:NSCaseInsensitiveSearch range:wholeString];
[escaped replaceOccurrencesOfString:@"\n" withString:@"%0A" options:NSCaseInsensitiveSearch range:wholeString];

Build push notification with urban airship

http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk_apns/

Convert CGPoint, CGRect or CGSize to String


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint previousPoint1 = [touch previousLocationInView:self];
    NSLog(@"touch begin %@", NSStringFromCGPoint(previousPoint1));
}


NSStringFromCGRect(CGRect rect)
NSStringFromCGSize(CGSize size)

Hide Keyboard when tap return in textview


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    
    return YES;
}

Tap anywhere to hide Keyboard


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapAnywhere:)];
    self.singleTapRecognizer.numberOfTapsRequired = 1;
    self.singleTapRecognizer.cancelsTouchesInView = NO;
}

-(void)didTapAnywhere: (UITapGestureRecognizer*) recognizer {    
    //[textField resignFirstResponder];
    [self.view endEditing:YES];
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    NSLog(@"add gesture recg");
    [self.view addGestureRecognizer:singleTapRecognizer];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    NSLog(@"remove gesture recg");
    [self.view removeGestureRecognizer:singleTapRecognizer];
}

Stretching an UIImage while preserving the corners




 original image


 result














myImageView.image = [myImageView.image resizableImageWithCapInsets:UIEdgeInsetsMake(20.f, 12.f, 19.f, 19.f)];


For lower iOS version, use 

[UIImage stretchableImageWithLeftCapWidth:15 topCapHeight:13];

Blur Effect

Add QuartzCore Framework
Add this to the beginning of the AppDelegates.h


#import <QuartzCore/QuartzCore.h>

@interface CAFilter : NSObject 
@end

Add this to the didFinishLaunchingWithOptions method (before makeKeyAndVisible call)


CAFilter* filter = [CAFilter filterWithName:@"gaussianBlur"];
[filter setValue:[NSNumber numberWithFloat:5] forKey:@"inputRadius"];
window.layer.filters = [NSArray arrayWithObject:filter];

Other way you can use this in UIView:

- (IBAction)toggleBlur {
    CALayer *layer = [self.blurView layer];
    blur = !blur;
    if (blur) {
        [layer setRasterizationScale:0.3];
        [layer setShouldRasterize:YES];
    } else {
        [layer setRasterizationScale:1.0];
        [layer setShouldRasterize:NO];
    }
}


See the other static filters available at:

Resize UIImage


+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}