2
我想使UISwitch周围的触摸区域每边增大10个点。看看相关文章(UIButton: Making the hit area larger than the default hit area)中的一些建议,我尝试使用下面的方法增加UISwitch周围的框架,但它会导致整个UISwitch拉伸以填充新框架。UISwitch:使触摸区域大于默认触摸区域
有没有更合理的方法可以做到这一点?
// Increase margin around switch based on width
const CGFloat desiredWidth = 260.0f; // real width is 240
const CGFloat margin = 0.5f * (desiredWidth - self.beginSwitch.frame.size.width);
// Add margin on all four sides of the switch
CGRect newFrame = self.beginSwitch.frame;
newFrame.origin.x -= margin;
newFrame.origin.y -= margin;
newFrame.size.width += 2.0f * margin;
newFrame.size.height += 2.0f * margin;
self.beginSwitch.frame = newFrame;
将一个不可见的按钮放在它的顶部,当它被击中时,设置实际开关的按钮状态 – trumpetlicks
也许作为最后的手段,将工作。这种方法的问题是用户不能像他们期望的那样滑动交换机。 –
好点,我想我永远不会滑动开关,我总是点击他们大声笑 – trumpetlicks