但是当我用别人的手给这个应用程序时,这个人会点击一个按钮,它将无法正常工作。感觉按钮只是对特定水龙头的反应,实际上感觉不对(如果你将它与正常行为进行比较)。
我该怎么做才能让它表现正常?正常意味着习惯iOS应用程序的人可以像他一样使用它,除非它有效。
以下是按钮的示例代码:
focusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2, 36, 40)];
focusButton.contentHorizontalAlignment = false; // I think these lines doesn't effect the behavior
focusButton.contentVerticalAlignment = false;
[focusButton setBackgroundImage:[UIImage imageNamed:@"arrowUp.png"] forState:UIControlStateNormal];
[focusButton setBackgroundImage:[UIImage imageNamed:@"arrowUpH.png"] forState:UIControlStateHighlighted];
[focusButton addTarget:self action:@selector(focusOrDefocusCourse) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:focusButton];
按钮背景如下所示:
答案 0 :(得分:2)
这是很好的..一旦用框架测试..
UIButton *btn_foucs = [UIButton buttonWithType:UIButtonTypeCustom];
[btn_foucs setFrame:CGRectMake(20, 20, 200, 40)];
[btn_foucs setImage:[UIImage imageNamed:@"btn_erase.png"] forState:UIControlStateNormal];
[btn_foucs setImage:[UIImage imageNamed:@"btn_erase_h.png"] forState:UIControlStateHighlighted];
[self.view addSubview:btn_foucs];
答案 1 :(得分:1)
您可以查看UIButton属性imageEdgeInsets
。这使您可以将图像绘制到帧的一部分,使可触摸区域大于图像本身(减少“丢失”按钮的可能性)。您可以执行以下操作,例如:
int touch_offset = 10;
[focusButton setFrame:CGRectMake(self.bounds.size.width-(self.bounds.size.width/widthFactor)+108-touch_offset, self.bounds.origin.y+(self.bounds.size.height/(heightFactor*2))+2-touch_offset, 36+(touch_offset*2), 40+(touch_offset*2))];
focusButton.imageEdgeInsets = UIEdgeInsetsMake(touch_offset, touch_offset, touch_offset, touch_offset);
这应使可触摸区域比每侧的图像宽10个像素,可通过更改touch_offset值进行调整。作为一般准则,Apple建议使用不小于44x44像素的可触摸区域。