UIAlertView button frames - all 0?

Is there a way to get a link to the button frames in the generated alertView? I would like to find the position of the top button so that I can use its frame to position the image directly above it. I have a couple extra \ n at the end of my alertview message to make sure there is space for the image, but I need to determine where this free space is in alertview mode. Using the top button as a link seems like a reliable way to find it.

I tried the following, which returns an array of buttons (ThreePartButton ??), but if the size of each button is set, then for x of them they are 0.

NSArray *buttonArray = [alertView valueForKey:@"_buttons"];
for (UIControl *aControl in buttonArray)
{
  CGRect rect = aControl.frame;
  NSLog(@"x:%2.2f y:%2.2f w:%2.2f h:%2.2f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}

Any suggestions for a working solution would be highly appreciated!

+2
source share
1 answer

the trick is that presentation frames are computed immediately before the show. so use UIAlertViewDelegate (the class where you create your UIAlertView, for example) and implement

- (void)willPresentAlertView:(UIAlertView *)alertView

delegate method. You will gain access to the computed UIButton frame.

+5
source

Source: https://habr.com/ru/post/1766515/


All Articles