ios指针问题

时间:2012-10-29 09:47:21

标签: iphone ios pointers

嗨,有些指针问题,这是我的代码

NSArray *buttons = [NSArray arrayWithObjects: self.btn1, self.btn2, self.btn3,nil];

 for(UIButton *btn in buttons){

    NSLog(@"%f, %f, %@", btn.bounds.size.width, btn.frame.size.height,  btn.titleLabel.text);
 }

输出为"0.00000, 0.00000, button1" 任何想法都出错了???

1 个答案:

答案 0 :(得分:0)

使用此代码重试只需在viewDidLoad:方法中设置框架,如下图..

- (void)viewDidLoad
{

    ///set frame which you want..

    self.btn1 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 100, 44)];
    self.btn2 = [[UIButton alloc]initWithFrame:CGRectMake(10, 70, 100, 44)];
    self.btn3 = [[UIButton alloc]initWithFrame:CGRectMake(10, 120, 100, 44)];
}