Search code examples
iphoneobjective-cframecgrectcustom-cell

How to find the x , y position of button frame in a custom cell


I made a table view with a custom cell as follows.

![Custom cell][1]

![Out put table view][2]

i need to set ratings using picker instead of slider in each cell

enter image description here

I need to set picker position only on just bellow the button it will varie with respective to the button postion

how to achieve it.

iu tried with fram & bounds as follow but give same vaues every time

   - (IBAction) buttonClicked:(UIButton *)sender
    {      
          NSLog(@"------%f  %f",sender.frame.origin.x , sender.frame.origin.y); //250, 2

         NSLog(@"------%f  %f",sender.bounds.origin.x , bounds.frame.origin.y); // 0.0 , 0.0

       picker.frame = CGRectMake(sender.bounds.origin.x , sender.bounds.origin.y, 50, 216);
}

Solution

  • You have a typo in your last line where you use the ".x" value twice, instead of using the ".y" value the second time.

    Also, you need to convert the coordinates to the coordinates of the view that the picker is being displayed in. Include the code for showing your picker and I can help you with that.

    It will be something like this:

    picker.frame = [viewThatYouAreDisplayingThePickerIn convertRect:sender.frame fromView:sender.superview];