UIView
我在课堂上创建了一个习惯。然后我将它添加到我的屏幕上,我想知道它是CGRect
. 但从表面上看,我似乎无法得到这个特定的大小UIView
。这是我的代码:
CGRect labelFrame;
if (!tickerImage) {
labelFrame = CGRectMake(upperTextField.frame.origin.x + 8, upperTextField.frame.origin.y, 0, 0);
} else {
labelFrame = CGRectMake(upperTextField.frame.origin.x + 16, upperTextField.frame.origin.y, 0, 0);
}
SGNewLabel = [[SGAdressLabel alloc] initWithFrame:labelFrame];
[labelsArray addObject:SGNewLabel];
[self.view addSubview:SGNewLabel];
[SGNewLabel addNewLabelWithText:labelText andTickerImage:tickerImage];
UIView *lastLabel = [labelsArray lastObject];
CGRect newTextFieldFrame = CGRectMake(lastLabel.frame.origin.x + lastLabel.frame.size.width, labelFrame.origin.y, 320, 30);
upperTextField.frame = newTextFieldFrame;
如您所见,我upperTextField
根据自定义的框架设置框架,SGNewLabel
这似乎是错误的,即使放入NSArray
. 我0, 0
在声明的末尾设置,labelFrame
因为我不知道未来对象的大小,这就是我的问题的根源。
我怎样才能纠正它并获得我的 UIView 的正确大小?
编辑:我认为的 NSLog 给了我这个:
NSLog(@"The rect of object is: %@", NSStringFromCGRect(self.frame));
2013-02-11 17:16:02.333 MyApp[2383:c07] The rect of object is: {{24, 55}, {0, 0}}
本身是正常绘制的UIView
,我可以看到它的全尺寸。