我创建一个像这样的 UIButton:
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,100,100);
按钮可以工作,但点击区域仅在文本上,而不是整个按钮。我已将按钮的背景设置为[UIColor clearColor]
。我需要做什么才能使按钮的整个框架都是点击区域?
我想我可以更改标签的框架以等于按钮,但这似乎很做作。有更好的办法吗?
最佳答案
尝试这样,
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0,0,100,100);
button.backgroundColor=[UIColor clearColor];
[button setTitle:@"Set" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:button];
关于iphone - 点击区域仅位于 UIButton 的标签上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12754899/