Guest User

ios palette

a guest
Jan 16th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Here I am passing the values to the array.
  2. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  3.    
  4.     UITouch *touch = [touches anyObject];
  5.     CGPoint lastPoint = [touch locationInView:self.ColorPickerImageView];
  6.     UIColor *color = [self getPixelColorAtLocation:lastPoint];
  7.     if ([touch tapCount] == 2) {
  8.         //self.imageView.image = nil;
  9.          arrayOFPalette = [[NSMutableArray alloc] init];
  10.         if (self.imgView1.backgroundColor == nil)
  11.         {
  12.             self.lbl1.text = hexsTring;
  13.             self.imgView1.backgroundColor = color;
  14.              
  15.         }
  16.         else if
  17.             (self.imgView2.backgroundColor == nil)
  18.         {
  19.             self.lbl2.text = hexsTring;
  20.             self.imgView2.backgroundColor = color;
  21.                
  22.         }
  23.         else if  (self.imgView3.backgroundColor == nil)
  24.         {
  25.             self.lbl3.text = hexsTring;
  26.             self.imgView3.backgroundColor = color;
  27.         }
  28.         else if (self.imgView4.backgroundColor == nil)
  29.         {
  30.             self.lbl4.text = hexsTring;
  31.             self.imgView4.backgroundColor = color;
  32.            
  33.         }
  34.         else if (self.imgView5.backgroundColor == nil)
  35.         {
  36.             self.lbl5.text = hexsTring;
  37.             self.imgView5.backgroundColor = color;
  38.            
  39.         }
  40.         else
  41.         {
  42.             [self showErrorAlert];
  43.         }
  44.  
  45.         [arrayOFPalette addObject:self.lbl1.text];
  46.         [arrayOFPalette addObject:self.lbl2.text];
  47.         [arrayOFPalette addObject:self.lbl3.text];
  48.         [arrayOFPalette addObject:self.lbl4.text];
  49.         [arrayOFPalette addObject:self.lbl5.text];
  50.  
  51.  
  52.      
  53.      
  54.        
  55.      
  56.         return;
  57.     }
  58.       NSLog(@"%@",arrayOFPalette);
  59.    
  60.       NSLog(@"color is : %@",color);
  61.       NSLog(@"%f",lastPoint.x);
  62.       NSLog(@"%f",lastPoint.y);
  63.    
  64.       self.selectedColorView.backgroundColor = color;
  65.    
  66. }
  67.  
  68. And here is the button event.
  69. - (IBAction)btnSearchPalette:(id)sender {
  70.     if (arrayOFPalette != nil) {
  71. //        int myCount = 0;
  72. //        while (myCount <= arrayOFPalette.count) {
  73. //            NSLog(@"iteration %d",myCount);
  74. //            myCount++;
  75. //            NSString *indexValue = [arrayOFPalette objectAtIndex:0];
  76. //            NSLog(@"index 0 have %@",indexValue);
  77. //            if ([arrayOFPalette objectAtIndex:1] == [NSNull null])
  78. //            {
  79. //                NSLog(@"index is null");
  80. //            }else{
  81. //                NSLog(@"has value");
  82. //            }
  83. //        }
  84.         NSURL *url = [NSURL URLWithString:@"http://localhost/ColorPicker/search.php"];
  85.        
  86.         NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
  87.      
  88.         NSString *messageBody = [NSString stringWithFormat:@"color=%@",arrayOFPalette];
  89.                  // if I just send a single value e.g; #ff88bc the api respond fine
  90.         NSData *postData = [messageBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
  91.        
  92.         NSString *msgLength = [NSString stringWithFormat:@"%d", [postData length]];
  93.        
  94.         [theRequest setHTTPMethod:@"POST"];
  95.        
  96.         [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  97.        
  98.         [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  99.        
  100.         [theRequest setHTTPBody:postData];    //[color dataUsingEncoding:NSUTF8StringEncoding]];
  101.        
  102.         NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  103.        
  104.         if(theConnection)
  105.            
  106.         {
  107.             NSLog(@"Connection Successful");
  108.            
  109.             NSURLResponse *response;
  110.            
  111.             NSError *err;
  112.            
  113.             NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
  114.            
  115.            // NSLog(@"responseData here is: %@", responseData);
  116.            
  117.             NSString *resPonseGot = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
  118.            
  119.             NSLog(@"Response ==> %@", resPonseGot);
  120.            
  121.             NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  122.            
  123.      
  124.             imgURLArray =[str componentsSeparatedByString:@","];
  125.            
  126.      
  127.     }
  128.         // here I am passing result array containing url of images to the other array and sending to the gallery so that they can be viewed
  129.        
  130.         ViewController *customImageGallery = [[ViewController alloc] init];
  131.         customImageGallery.imgArrayfromURL = imgURLArray;
  132.         if (imgURLArray != nil) {
  133.             [self.navigationController pushViewController:customImageGallery animated:YES];
  134.         }
  135.         else{
  136.             [self alertStatus:@"Sorry No Matching Found" :@"Sorry!"];
  137.         }
  138.  
  139.        
  140.     }
  141.     else{
  142.         UIAlertView *ArrayAlert = [[UIAlertView alloc] initWithTitle:@"Empty Palette"
  143.                                                            message:@"Please Select Some Colors" delegate:nil
  144.                                                  cancelButtonTitle:nil
  145.                                                  otherButtonTitles:@"OK", nil];
  146.         [ArrayAlert show];
  147.        
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment