2012-04-20 58 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];