iphone - 点击区域仅位于 UIButton 的标签上

标签 iphone ios ipad uibutton cgrect

我创建一个像这样的 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/

相关文章:

iphone - UITableViewCell imageView 不显示

ios - Ipad 数字仅在两个文本字段之一中

objective-c - 在 UIScrollView 中滚动 UITableView

iphone - 获取 NSMutableData 的长度

iphone - 自动选择第一个 UITableView 文本框

iphone - 有什么好的iPhone声音管理框架吗?

iphone - 从 MapView calloutAccessoryControlTapped 使用 segue

ios - 使用 Alamofire ObjectMapper 映射到显示 nil 的 Swift 对象问题

ios - 正则表达式仅选择特殊字符包围的单词

iphone - 缺少 Facebook oauth/access_token