我的应用中有一个 UIButton,它非常小。有时很难点击它。有没有办法在按钮周围留出 20px 的边距,保持图像大小相同?这是我的代码:
self.helpButton= [UIButton buttonWithType:UIButtonTypeCustom];
[self.helpButton setImage:[UIImage imageNamed"Info Button.png"] forState:UIControlStateNormal];
[self.helpButton addTarget:self
actionselector(showHelp)
forControlEvents:UIControlEventTouchUpInside];
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
self.helpButton.frame = CGRectMake(280.0, 528.0, 20, 20);
} else {
self.helpButton.frame = CGRectMake(280.0, 440.0, 20, 20);
}
基本上,我希望有更大的点击区域,但保持按钮大小相同。
Best Answer-推荐答案 strong>
尝试使用 setImageEdgeInsets。检查一下。
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
self.helpButton.frame = CGRectMake(280.0, 528.0, 40, 40);
} else {
self.helpButton.frame = CGRectMake(280.0, 440.0, 40, 40);
}
[self.helpButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
关于ios - 设置 UIButton 的框架但保持图像大小相同,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/20573018/
|