我无法在UIView上添加按钮。我有UIView我想在其中添加UIButton。
这是我想要实现的代码。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setMultipleTouchEnabled:NO];
path = [UIBezierPath bezierPath];
[path setLineWidth:1.0];
_button = [UIButton buttonWithType:UIButtonTypeCustom];
[_button setTitle:@"" forState:UIControlStateNormal];
_button.userInteractionEnabled=YES;
_button.frame =CGRectMake(50, 130, 100, 100);
_button.backgroundColor =[ UIColor redColor];
[_button addTarget:self
action:@selector(buttonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_button];
}
return self;
}