0

i want to split the view into three different parts.each part i want to set different color. i have tried using drawing methods in drawrect.i've succeded but the splitting should be done on button click. here is the code that i have used.

          -(void)drawRect:(CGRect)rect
            {
        int i=0;
        float width =rect.size.width/[elements count];
         CGRect paintRect;
         for (NSString *color in self.elements) 
        {
        paintRect = CGRectMake(rect.origin.x+(i*width), rect.origin.y, width, rect.size.height);
    i++;

    UIColor *colorr=[UIColor colorWithHexString:color];
    [colorr set]; 
    UIRectFill(paintRect);

       }

      }

enter code here

now i want to use this code on button click..... help...thanx in advanced

1 Answers1

0

a much easier way to do this would be to put three custom buttons or custom views and arrange them in code.

Put the backcolor of the button or view to the selections you want.

And in the case of button you attach the UIControlEventTouchUpInside event and trap the touch.

in the case of a view. you would subclass the view and override the touch events associated to that view and build your own "click" event

This is a lot less complicated than trying to create your own touch locations in a single view.

Another option would be to grab the color at the pixel that is touched. there are a lot of examples of this on stackoverflow. here is one

Hope that helps

Community
  • 1
  • 1
The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69