在我的 UIView 子类(我在 Interface Builder 中实例化)中,有几个按钮作为子视图,我在 initWithCoder 方法中添加到我的视图中,如下所示:
theButton = [UIButton buttonWithType:UIButtonTypeCustom];
[theButton setFrame:CGRectMake([UIScreen mainScreen].bounds.size.height-150-10, 289, 150, 21)];
[theButton.titleLabel setTextAlignment:UITextAlignmentRight];
[theButton setOpaque:YES];
[theButton.titleLabel setFont:[UIFont fontWithName:@"MyFont" size:32.0]];
[theButton.titleLabel setTextColor:[UIColor redColor]];
[theButton.titleLabel setText:@"text"];
[self addSubview:theButton];
[theButton addTarget:myTarget action:@selector(pause) forControlEvents:UIControlEventTouchUpInside];
但是按钮不会按预期绘制。drawRect:
如果我在和po [self subviews]
llvm中设置断点,我会得到这个输出。
$0 = 0x0c93e860 <__NSArrayM 0xc93e860>(
<UIButton: 0xc93d910; frame = (10 289; 150 21); alpha = 0.5; layer = <CALayer: 0xc93d4a0>>,
<UIButton: 0xc93e2d0; frame = (408 289; 150 21); layer = <CALayer: 0xc93e390>>
)
那么为什么我的按钮不显示呢?
编辑:我的超级视图的递归描述:
<UIView: 0xa46b220; frame = (0 0; 320 568); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0xa46b280>>
| <MyView: 0xa168710; frame = (0 0; 568 320); autoresize = W+H; layer = <CALayer: 0xa1687d0>>
| | <UIButton: 0xa16c160; frame = (10 289; 150 21); alpha = 0.5; layer = <CALayer: 0xa16bcc0>>
| | | <UIButtonLabel: 0xa16c3e0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa16c480>>
| | <UIButton: 0xa16cb00; frame = (408 289; 150 21); layer = <CALayer: 0xa16cbc0>>
| | | <UIButtonLabel: 0xa16c7e0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa16c880>>