gpt4 book ai didi

iOS系统按钮点击框问题

转载 作者:行者123 更新时间:2023-11-29 02:28:41 25 4
gpt4 key购买 nike

问题: 某些系统 UIButton 类型 可以在其定义的框架/边界之外点击。

以下两种按钮类型在其定义的框架区域内被正确选择。

UIButtonTypeCustom [width:160, height:44.0]
UIButtonTypeSystem [width:50, height:44.0]

以下按钮类型甚至可以在其框架矩形之外从所有边选择 10~15 点。[背景颜色在所有这些按钮的定义框架中绘制/显示]

UIButtonTypeDetailDisclosure,[width:50, height:44.0]
UIButtonTypeInfoLight, [width:50, height:44.0]
UIButtonTypeInfoDark, [width:50, height:44.0]
UIButtonTypeContactAdd [width:50, height:44.0]

我希望可点击/可选择的区域应该在按钮框架中。

我正在使用以下方法创建按钮:

- (UIButton*)createButton:(UIButtonType)style withFrame:(CGRect)frame {

UIButton *button = nil;
UILabel *label = nil;
switch(style)
{
case UIButtonTypeCustom: // frame: {x,y,160.0,44.0}
button = [[UIButton alloc] initWithFrame:frame];
button.layer.cornerRadius = 10;

label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 160.0, 44.0)];
label.text = @"Custom";
label.textAlignment = NSTextAlignmentCenter;
[button addSubview:label];

break;

case UIButtonTypeSystem: // frame: {x,y,50.0,44.0}
button = [UIButton buttonWithType:style];
[button setTitle:@"Button" forState:UIControlStateNormal];
button.frame = frame;
break;

default: // frame: {x,y,50.0,44.0}
button = [UIButton buttonWithType:style];
button.frame = frame;
break;
}

// Background whitecolor is displaying properly for all buttons.
button.backgroundColor = [UIColor whiteColor];
return button;

createButton方法调用如下

for (int i=0, y=10, x=15; i<6; ++i) {
if(i == 5)
{
y += 90;
x = ([[UIScreen mainScreen] bounds].size.width - 160.0)/2.0;
}

UIButton *btn = [self createButton:5-i withFrame:CGRectMake(x, y, ( i<5 ? 50.0 : 160.0), 44.0)];
[btn setTag: i+1];
[btn addTarget:self action:@selector(settingsView:) forControlEvents:UIControlEventTouchUpInside];
[_subView addSubview:btn];

x += 60;
}

最佳答案

iOS 通常会根据自己的内部规则扩展按钮的可触摸区域。

我的猜测:它使用户更容易触摸按钮。

关于iOS系统按钮点击框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27181859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com