Friday, 22 June 2012

Change Image Size With Slider and Also with Max value To Min Value(Opposite Direction Logic )

Here in my app Big To Small Slider Image Display so i create bellow logic and complete the work...
In Bellow Method i zoom in and zoom out the Image with Slider....


    float finalval,fixfinal;
    if (sldBigSmall.value<500) {
    else if(sldBigSmall.value>500){
    if (boolimgplant) {

        imgplant.frame=CGRectMake(imgplant.frame.origin.x, imgplant.frame.origin.y, fixfinal, fixfinal);
        [imgplant setCenter:CGPointMake(500, 300)];
    else if(boolimgpot){
        imgpot.frame=CGRectMake(imgpot.frame.origin.x, imgpot.frame.origin.y, fixfinal,fixfinal);
        [imgpot setCenter:CGPointMake(500, 400)];

Thursday, 21 June 2012

Store Array in UserDefaults and also Update and Remove Facility.

In AppDelegate.h file just declare variable...
NSUserDefaults  *userDefaults;
NSMutableArray *arrAppFavPot;
NSMutableArray *arrAppFavPlant;


In AppDelegate.m Fille in applicationDidFinishLonching: Method

userDefaults = [NSUserDefaults standardUserDefaults];
    NSData *dataRepresentingtblArrayForSearch = [userDefaults objectForKey:@"arrAppFavPot"];
    if (dataRepresentingtblArrayForSearch != nil) {
        NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingtblArrayForSearch];
        if (oldSavedArray != nil)
            arrAppFavPot = [[NSMutableArray alloc] initWithArray:oldSavedArray];
            arrAppFavPot = [[NSMutableArray alloc] init];
    } else {
        arrAppFavPot = [[NSMutableArray alloc] init];
    [arrAppFavPot retain];
    NSData *dataRepresentingtblArrayForSearchPlant = [userDefaults objectForKey:@"arrAppFavPlant"];
    if (dataRepresentingtblArrayForSearchPlant != nil) {
        NSArray *oldSavedArrayPlant = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingtblArrayForSearchPlant];
        if (oldSavedArrayPlant != nil)
            arrAppFavPlant = [[NSMutableArray alloc] initWithArray:oldSavedArrayPlant];
            arrAppFavPlant = [[NSMutableArray alloc] init];
    } else {
        arrAppFavPlant = [[NSMutableArray alloc] init];
    [arrAppFavPlant retain];

after that when you want to insert,update or delete Data from this UserDefaults Use Bellow Code...

        [appDelegate.arrAppFavPot removeObjectAtIndex:carouselPot.currentItemIndex];
        [appDelegate.arrAppFavPot addObject:[arrPot objectAtIndex:carouselPot.currentItemIndex]];
    NSData *data=[NSKeyedArchiver archivedDataWithRootObject:appDelegate.arrAppFavPot];
    [appDelegate.userDefaults setObject:data forKey:@"arrAppFavPot"];
    [appDelegate.userDefaults synchronize];

Monday, 18 June 2012

CaptureImage(ScreenShot Of View).

This Code Useful when user wants to capture current view ScreenShot and share or save this image....

- (UIImage *)captureView {

//hide controls if needed
CGRect rect = [self.view bounds];
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    return img;


If the view contains the layer images or some graphics related data then use below method.

-(UIImage *)convertViewToImage:(UIView *)viewTemp
    [viewTemp drawViewHierarchyInRect:viewTemp.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    return image;


See my this Answer Also.... howe-to-capture-uiview-top-uiview

Saturday, 16 June 2012

Best Method for Change Image Color ....

- (UIImage *)imageNamed:(UIImage *)newimg withColor:(UIColor *)color{
    // load the image
    //    NSString *name = @"badge.png";
    UIImage *img = newimg;
    // begin a new image context, to draw our colored image onto
    // get a reference to that context we created
    CGContextRef context = UIGraphicsGetCurrentContext();
    // set the fill color
    [color setFill];
    // translate/flip the graphics context (for transforming from CG* coords to UI* coords
    CGContextTranslateCTM(context, 0, img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    // set the blend mode to color burn, and the original image
    CGContextSetBlendMode(context, kCGBlendModeColor);
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
    CGContextDrawImage(context, rect, img.CGImage);
    // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
    CGContextClipToMask(context, rect, img.CGImage);
    CGContextAddRect(context, rect);
    // generate a new UIImage from the graphics context we drew onto
    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    //return the color-burned image
    return coloredImg;

Friday, 15 June 2012

Local Notification in iPhone SDK.....Code

I Have 2Methods For LocalNotification alarm....

    NSLog(@"\n ----------->>Go Clicked");
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
        NSString *kRemindMeNotificationDataKey = @"kRemindMeNotificationDataKey";

        NSDateComponents *dc = [[NSCalendar currentCalendar] components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSQuarterCalendarUnit fromDate:[exdatePicker date]];
        [dc - 1];
        NSDate *noticeDate = [[NSCalendar currentCalendar] dateFromComponents:dc];

        NSDateFormatter* dateFormatterstring = [[NSDateFormatter alloc] init];
        [dateFormatterstring setDateFormat:@"dd-MM-yyyy hh:mm:ss a"];
        NSString *dateString = [dateFormatterstring stringFromDate:noticeDate];

        txtExpirayDate.text = dateString;
        UILocalNotification *notification = [[cls alloc] init];

        notification.fireDate = noticeDate;
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.alertBody = [NSString stringWithFormat:@"%@ your Licence Expiry Date is Tommorow",txtLicence.text];
        notification.alertAction = @"Show me";
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.applicationIconBadgeNumber = 1;
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:txtLicence.text forKey:kRemindMeNotificationDataKey];
        notification.userInfo = userDict;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];
and another is..

- (IBAction) scheduleAlarm:(id) sender {
    [eventText resignFirstResponder];
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    // Get the current date
    NSDate *pickerDate = [self.datePicker date];
    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
 // Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
 [dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
 // Notification details
    localNotif.alertBody = [eventText text];
 // Set the action button
    localNotif.alertAction = @"View";
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;
 // Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    localNotif.userInfo = infoDict;
 // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
 [self.tableview reloadData];

Monday, 4 June 2012

Create Custom Button with multiple line....

Allow you to setup max. no. of line

Button’s size varies with length of title. Button can’t support multiple lines and linebreak. Using background image or frame won’t support multiple lines. It’s possible to addSubview a UILabel to the button.
UIButton *button;
// Set UIbutton type
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// Set UIbutton background image for Normal state
[button setBackgroundImage:img forState:UIControlStateNormal];
// Set UIButton background image for Highlighted state
[button setBackgroundImage:buttonBackgroundPressed forStates:UIControlStateHighlighted];
// Set UIButton title for Normal, Highlighted, Selected States
[button setTitle:@"Normal State" forState:UIControlStateNormal];
[button setTitle:@"Highlighted State" forState:UIControlStateHighlighted];
[button setTitle:@"Selected State" forState:UIControlStateSelected];
// Set UIButton font
button.font = [UIFont boldSystemFontOfSize:BUTTON_FONT_SIZE];
// Set UIButton horizontal and vertical alignment
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
// Assign method to UIButton action and control event
[button addTarget:self action:@selector(buttonMethod) forControlEvents:UIControlEventTouchUpInside];
// set UIButton to center = CGPointMake( 45.0, 240.0);
// set UIButton background color
button.backgroundColor = [UIColor clearColor];
// addSubview to UIButton
[ContentView addSubview:oneButton];
// release UIButton memory

[button release];