Tuesday, 4 March 2014

Set and get Date in NSString format or NSDate format with different date format with my bellow method

You can get date with string return type and also set date format in which you want to get date For Ex: dd-MMM-yyyy (i.e. 05-Mar-2014)

-(NSString *)changeDateFormat:(NSString*)stringDate dateFormat:(NSString*)dateFormat getwithFormat:(NSString *)getwithFormat{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    NSDate *date = [dateFormatter dateFromString:stringDate];
    [dateFormatter setDateFormat:getwithFormat];
    NSString *convertedString = [dateFormatter stringFromDate:date];
    NSLog(@"Converted String : %@",convertedString);
    return convertedString;

NSString  *stringVar  = [self changeDateFormat:yourDateString dateFormat:@"yyyy-MM-dd" getwithFormat:@"dd MMM yyyy"];// set your date string and its date format and after set your required new date format

You can get date with NSDate return type and also set date format in which you want to get date For Ex: dd-MMM-yyyy (i.e. 05-Mar-2014) same like above but here you get return date in NSDate.

-(NSDate *)convertStringToDate:(NSString *)date dateFormat:(NSString *)dateFormat getWithFormat:(NSString *)getWithFormat {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSDate *nowDate = [[NSDate alloc] init];
    [formatter setDateFormat:dateFormat];// set format here which format in string date
    date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""];
    nowDate = [formatter dateFromString:date];
    [formatter setDateFormat:getWithFormat];
    NSString *convertedString = [formatter stringFromDate:nowDate];
    nowDate = [formatter dateFromString:convertedString];
    // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate);
    return nowDate;


set size of UILable with its content text

With my bellow method you can set UILable size with its content text.

-(CGRect)setDynamicHeight:(UILabel *)lbl{
    CGRect myLabelFrame = [lbl frame];
    NSString *text = lbl.text;
    CGFloat width = lbl.frame.size.width;
    UIFont *font = lbl.font;
    NSAttributedString *attributedText =
    [[NSAttributedString alloc]
     NSFontAttributeName: font
    CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX}
    CGSize size = rect.size;
    myLabelFrame.size.height = size.height;
    return myLabelFrame;


and use this method with my bellow code

    [yourLable setFrame:[self setDynamicHeight:yourLable]];

Monday, 3 March 2014

How to add animation in View for any view or any Control.

With bellow code you can set animation for any control or any view...

        CATransition *animation = [CATransition animation];
        [animation setDuration:1.0];// Set Duration
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromTop];// set different type of Transition
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

        [[yourView layer] addAnimation:animation forKey:@"SwitchToView1"];// here you can set any view or any Control For Ex: UITableViewCell