1

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

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

1 回答 1

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];
于 2012-05-25T16:26:20.947 回答