Friday, 7 November 2014

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

Title for refresh controller (UIRefreshControl)

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                            forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
self.refreshControl.attributedTitle = attributedTitle;

No results Tableview

When data source count is zero create a label with no result message and add it as the background view of table view

 UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    messageLabel.text = @"No data is currently available.";
    messageLabel.textColor = [UIColor blackColor];
    messageLabel.numberOfLines = 0;
    messageLabel.textAlignment = NSTextAlignmentCenter;
    messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20];
    [messageLabel sizeToFit];
    self.tableView.backgroundView = messageLabel;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Monday, 21 July 2014

Dynamic Height For UILabel

label.textAlignment= NSTextAlignmentCenter;
label.lineBreakMode= NSLineBreakByWordWrapping;
label.numberOfLines=0;
CGSize newSize = [label.text boundingRectWithSize:CGSizeMake(label.frame.size.width, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:label.font}context:nil].size;
CGRect labelFrame=label.frame;
labelFrame.size.height=newSize.height;
label.frame=labelFrame;

Wednesday, 16 July 2014

Remove all subviews of a view

[[someUIView subviews]
 makeObjectsPerformSelector:@selector(removeFromSuperview)]

CABasicAnimation Examples

UIView *AnimView1=[[UIView alloc] initWithFrame:CGRectMake(30, 50, 50, 50)];
AnimView1.backgroundColor=[UIColor greenColor];
[self.view addSubview:AnimView1];

UIView *AnimView2=[[UIView alloc] initWithFrame:CGRectMake(90, 75, 50, 50)];
AnimView2.backgroundColor=[UIColor orangeColor];
[self.view addSubview:AnimView2];

UIView *AnimView3=[[UIView alloc] initWithFrame:CGRectMake(170, 90, 50, 50)];
AnimView3.backgroundColor=[UIColor yellowColor];
[self.view addSubview:AnimView3];

UIView *AnimView4=[[UIView alloc] initWithFrame:CGRectMake(240, 150, 50, 50)];
AnimView4.backgroundColor=[UIColor blueColor];
[self.view addSubview:AnimView4];

//shrink
CABasicAnimation* shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:0.5];
shrink.duration = 0.5;
shrink.delegate = self;
shrink.repeatCount=INFINITY;
shrink.autoreverses=YES;
[[AnimView1 layer] addAnimation:shrink forKey:@"shrinkAnim"];

//moving
CABasicAnimation *Animation1;
Animation1=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
Animation1.duration=0.2;
Animation1.repeatCount=INFINITY;
Animation1.autoreverses=YES;
Animation1.fromValue=[NSNumber numberWithFloat:0];
Animation1.toValue=[NSNumber numberWithFloat:-10];
[[AnimView2 layer] addAnimation:Animation1 forKey:@"shakeAnim"];

//rotating
CABasicAnimation *Animation2;
Animation2=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
Animation2.duration=0.2;
Animation2.repeatCount=INFINITY;
Animation2.autoreverses=YES;
Animation2.fromValue=[NSNumber numberWithFloat:0];
Animation2.toValue=[NSNumber numberWithFloat:M_PI/4];
[[AnimView3 layer] addAnimation:Animation2 forKey:@"rotateAnim"];

//fade
CABasicAnimation *animation3 = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation3.duration=0.5;
animation3.repeatCount=INFINITY;
animation3.autoreverses=YES;
animation3.fromValue=[NSNumber numberWithFloat:1];
animation3.toValue=[NSNumber numberWithFloat:0];
[[AnimView4 layer] addAnimation:animation3 forKey:@"fadeAnim"];  
Reference