Is there a way for me to get a reference to the button frames in an alertView I created? I'd like to find the position of the top button so I can use its frame to position an image directly above it. I have a couple of extra \n's at the end of my alertview text to make sure there is room to place the image, but I need to determine where that free space is in the alertview. Using the top button as a reference seems like a reliable way to find it.
I have tried the following, which does return the button array (ThreePartButton??), but while the size of each button is set, the x,y origin for all of them are 0.
NSArra开发者_如何转开发y *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 much appreciated!
the trick is that the view's frames are computed just before showing. so use a UIAlertViewDelegate (the class where you create your UIAlertView for example) and implement the
- (void)willPresentAlertView:(UIAlertView *)alertView
delegate method. You will access the computed UIButton's frame.
精彩评论