我创建了一个分段 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/