0

大家好,指针有问题,这是我的代码

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" 任何想法出了什么问题???

4

1 回答 1

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)];
}
于 2012-10-29T09:54:56.237 回答