【发布时间】:2015-07-08 16:30:08
【问题描述】:
我正在以编程方式使用 xib 初始化 UIView:
- (id)initWithFrame:(CGRect)frame
{
self = [[[NSBundle mainBundle] loadNibNamed:@"MyViewNib" owner:self options:nil] objectAtIndex:0];
if (self)
{
//perform setup of various components
return self;
}
}
此视图使用任意宽度、任意高度和任意宽度、紧凑高度的尺寸类。
我在 xib 中有一个 UIButton,我需要在其背景中放置一个圆圈,如下所示:
self.closeButton.layer.cornerRadius = self.closeButton.frame.size.width / 2.0f;
self.closeButton.layer.backgroundColor = [UIColor colorWithWhite:164.0f / 255.0f alpha:1.0f].CGColor;
如果我在使用任何宽度、紧凑高度的设备上时尝试在 init 函数中设置按钮的圆角半径,标签的框架仍设置为任何宽度、任何高度值。我也尝试过覆盖 layoutSubviews 并在那里设置值,但没有运气。似乎在 layoutSubviews 之后应用了尺寸类约束,而无需再次调用 layoutSubviews,因为其他组件正确显示在屏幕上。
所以,我想知道是否有一个很好的切入点让我了解尺寸类的应用位置,以便我可以正确设置按钮的背景角半径。我可以以编程方式设置按钮,但我想弄清楚如何做到这一点,因为它可能会在转换为大小类的过程中再次出现。
【问题讨论】:
标签: ios objective-c uiview xib size-classes