UIAlertView按钮框都是0? [英] UIAlertView button frames are all 0?

查看:81
本文介绍了UIAlertView按钮框都是0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让我在我创建的alertView中的按钮框架的引用?我想找到顶部按钮的位置,所以我可以使用它的框架来定位图像直接在它上面。我在alertview文本的末尾有几个额外的\ n,以确保有空间放置图像,但我需要确定在可见空间在alertview中的位置。使用顶部按钮作为参考看起来像一个可靠的方法来找到它。



我已经尝试过以下操作,它返回按钮数组(ThreePartButton ??),但是当每个按钮的大小设置时,所有的x,y原点的值为0。

  NSArray * buttonArray = [alertView valueForKey:@_ buttons]; 
for(UIControl * aControl in buttonArray)
{
CGRect rect = aControl.frame;
NSLog(@x:%2.2fy:%2.2fw:%2.2fh:%2.2f,rect.origin.x,rect.origin.y,rect.size.width,rect.size.height );
}

对于工作解决方案的任何建议都非常感谢!

$诀窍是视图的帧是在显示之前计算的。
所以使用UIAlertViewDelegate(例如你创建你的UIAlertView的类)并实现

   - (void) willPresentAlertView:(UIAlertView *)alertView 

委托方法。您将访问计算的UIButton的框架。


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.

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 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.

这篇关于UIAlertView按钮框都是0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆