gpt4 book ai didi

ios - 如何添加按钮的触摸区域?

转载 作者:行者123 更新时间:2023-11-29 11:58:44 24 4
gpt4 key购买 nike

selectgroup = [UIButton buttonWithType:UIButtonTypeCustom];
selectgroup.frame = CGRectMake(screenWidth/4-23/2, 158, 23, 23) ;
selectgroup.hidden = NO;
UIImage *selectgroupimg = [UIImage imageNamed:@"groupicon2.png"];
[selectgroup setBackgroundImage:selectgroupimg forState:UIControlStateNormal];
//[selectgroup setcontentEdgeInsets : UIEdgeInsetsMake(0, 150, screenWidht/2, 30)];
[selectgroup addTarget:self action:@selector(selectgroup:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:selectgroup];

我想将按钮的可点击区域增加到(0,150,screenwidth/2,30)。我尝试设置 contentEdgeInsetsimageEdgeinsets 但两者都不起作用。

我该怎么做?

最佳答案

你需要像这样设置图片(Button 属性 setImage 和 setBackgroundImage 都是不同的)

UIImage *btnImage = [UIImage imageNamed:@"image.png"];
[buttonObject setImage:btnImage forState:UIControlStateNormal];forState:UIControlStateNormal];

然后设置你想要的按钮框架

buttonObject.frame  = CGRectMake(0,150,screenwidth/2,30);

关于ios - 如何添加按钮的触摸区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37967067/

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