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

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

! [Custom cell] [1]

! [Out table table view] [2]

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

enter image description here

I need to set the position of the selection only when the button is pressed, which will change based on the position of the button

how to achieve this.

iu tried with border and borders as follows, but showing the same values ​​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);
}

      

+3


source to share


3 answers


You have a typo on your last line where you use the ".x" value twice instead of the second ".y" value.

Also, you need to convert coordinates to coordinates of the view that the collector will display. Include the code to show your collector and I can help you.



It will be something like this:

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

      

+5


source


But still, if you want to get the border of buttons relative to the main view Use this:



 CustomCell *cell = (CustomCell *)[self.table cellForRowAtIndexPath:indexPath];

 CGRect buttonFrame = [cell.superview convertRect:cell.customButton.frame toView:self.view];

      

+1


source


Button

has a method named locationInView

inherited fromUITouch

Returns the current location of the receiver in the coordinate system of the given view.
- (CGPoint)locationInView:(UIView *)view

      

Apple developer reference

0


source







All Articles