2012-04-20 53 views
1

我已经创建了一个分段控制器,它有不同大小的段。 当我检查我看到段控制器具有不同的宽度大小段,但是当我尝试触摸最大的段时,它只能在段的左侧部分上触及。 (可能只是第一个50像素的部分,但部分是160像素)。我如何设置细分受众群区域?UISegmentedControl段的大小触摸检测

//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]; 
} 

回答

1

我有同样的问题我自己......事实证明,如果不设置它的段的宽度之前设置分段控制本身的宽度,那么你得到这个同样的问题在这里。下面是一个在我的代码中修正了这个问题的例子(希望它有帮助!):

[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];