繁体   English   中英

UISegmentedView中的UIButton未被按下

[英]UIButton in UISegmentedView not getting pressed

我在UISegmentedView的一个UISegments中放置了一个自定义UIButton,但是以某种方式未按下此按钮。 我使用以下代码:

UIButton* button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0, 0, 103, 30);
[button addTarget:self action:@selector(handleSaleChange:) forControlEvents:UIControlEventAllTouchEvents];
button.backgroundColor=[UIColor redColor];
[[[self.segmentControl subviews]objectAtIndex:2] addSubview:button];
[self.segmentControl bringSubviewToFront:button];

知道为什么我会遇到这个问题吗? 谢谢!

该按钮是子视图的子视图 ,因此它不会很快触发,因为分段控件无论如何都会捕获其触摸。 将其添加为控件的子视图,然后重试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM