Sunday, 2 November 2014

Blurring Image

#import "UIImageEffects.h"

....

UIImage *blurdImage=[UIImageEffects imageByApplyingLightEffectToImage:[UIImage imageNamed:@"sample.png"]];
Apple Sample code with UIImageEffects classes

Round two corners of UIView

-(void) setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners withRadius:(CGFloat)radius;
{
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];

    view.layer.mask = shape;
}
// function Call
[self setMaskTo:view1 byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft withRadius:20.0];

Thursday, 30 October 2014

Add SubView with animation.

 myView.alpha=0;

    [mySuperView addSubview:myView];

    [UIView animateWithDuration:0.2
                         animations:^{myView.alpha = 1.0;}
                         completion:nil];

Remove View from SuperView with Animation

[UIView animateWithDuration:0.2
     animations:^{view.alpha = 0.0;}
     completion:^(BOOL finished){ [view removeFromSuperview]; }];

Sunday, 14 September 2014

Dictionary Lookup ( UIReferenceLibraryViewController )


    if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word.text]) {
        UIReferenceLibraryViewController* ref =
        [[UIReferenceLibraryViewController alloc] initWithTerm:word.text];
        [self presentViewController:ref animated:YES completion:nil];
    }else{

        NSLog(@"No definition found");
   }

Wednesday, 30 July 2014

Highlight Text in UIWebView using JavaScript

[webView stringByEvaluatingJavaScriptFromString:@"var range = window.getSelection().getRangeAt(0);"
    @"var selectionContents = range.extractContents();"
    @"var span = document.createElement('span');"
    @"span.style.backgroundColor = 'yellow';"
    @"span.appendChild(selectionContents);"
    @"range.insertNode(span)" ];

Monday, 28 July 2014

Shuffle Array

- (NSArray*)shuffleArray:(NSArray*)array {

    NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:array];

    for(NSUInteger i = [array count]; i > 1; i--) {
        NSUInteger j = arc4random_uniform(i);
        [temp exchangeObjectAtIndex:i-1 withObjectAtIndex:j];
    }

    return [NSArray arrayWithArray:temp];
}
Reference