ios - UISegmentedControl 段大小触摸检测

标签 ios touch uisegmentedcontrol

我创建了一个分段 Controller ,它有不同大小的分段。 当我检查时,我看到段 Controller 具有不同宽度大小的段,但是当我尝试触摸最大的段时,它只能在段的左侧部分被触摸。 (可能只是前 50 像素的部分,但片段是 160 像素)。如何设置段的可触摸区域?

//My header file:        
#import <UIKit/UIKit.h>
@interface Form1 : UIViewController <UIAlertViewDelegate>{
IBOutlet UISegmentedControl *combobox6001;
}
@property (nonatomic, strong) IBOutlet UISegmentedControl *combobox6001;
@end

#import "Form1.h"
@implementation Form1
@synthesize combobox6001;
- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [combobox6001 setWidth:50  forSegmentAtIndex:0];
    [combobox6001 setWidth:50  forSegmentAtIndex:1];
    [combobox6001 setWidth:160 forSegmentAtIndex:2];
}

最佳答案

我自己也遇到了同样的问题...事实证明,如果您在设置段控件宽度之前没有设置段控件本身的宽度,那么您会在这里遇到同样的问题。这是在我的代码中修复此问题的示例(希望对您有所帮助!):

    [topSegmentedControl setFrame:CGRectMake(5.0, 5.0, frame.size.width - 26.0, topSegmentedControl.frame.size.height)];

    float width1 = round(topSegmentedControl.frame.size.width * 0.125);
    float width2 = round(topSegmentedControl.frame.size.width * 0.175);
    float width3 = round(topSegmentedControl.frame.size.width * 0.275);
    float width4 = topSegmentedControl.frame.size.width - (width1 + width2 + width3 + 3.0);

    [topSegmentedControl setWidth:width1 forSegmentAtIndex:0];
    [topSegmentedControl setWidth:width2 forSegmentAtIndex:1];
    [topSegmentedControl setWidth:width3 forSegmentAtIndex:2];
    [topSegmentedControl setWidth:width4 forSegmentAtIndex:3];

关于ios - UISegmentedControl 段大小触摸检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10246124/

相关文章:

javascript - Hammer.js 阻止 iOS Safari 上的滚动事件

javascript - Touchend 第二次在 touchstart 上触发

android - 即使在拖动模式下,如何在我的 Activity 中获取所有触摸事件?

ios - 更改 UISegmentedControl 中特定段的标题文本颜色?

objective-c - IF 语句忽略最后一个条件

ios - 如何在 swift 中使用 fetchedresultscontroller 重新排序 tableview 行?

iphone - 使用分段控件在 2 个 View 之间切换

iOS - 防止 UIAppearance 设置更改 UIWebView 输入附件 View

iphone - 向单元格添加按钮

ios - 您的凭据不允许访问此资源 Twitter API 错误