我正在使用 segemntController,
我正在为段的按下状态和正常状态设置不同的不同图像,下面是我的代码
(void)viewdidLoad
{
NSArray *imageArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"image1"],[UIImage imageNamed:@"image2"],[UIImage imageNamed:@"image3"],nil];
m_segmentController = [[UISegmentedControl alloc]initWithItems:imageArray];
m_segmentController.frame = CGRectMake(50, 10, 212, 30);
m_segmentController.segmentedControlStyle = UISegmentedControlStyleBar;
m_segmentController.selectedSegmentIndex = 0;
[m_segmentController setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[m_segmentController addTarget:self action:@selector(segmentSelected:)forControlEvents:UIControlEventValueChanged];
[self.navigationController.navigationBar addSubview:m_segmentController];
}
- (IBAction)segmentSelected:(id)sender
{
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if(selectedSegment == 0)
{
[m_segmentController setImage:[UIImage imageNamed:@"image1.png"] forSegmentAtIndex:0];
}
else
{
[m_segmentController setImage:[UIImage imageNamed:@"image2png"] forSegmentAtIndex:1];
}
}
所以当我启动我的应用程序时,segmentController 看起来是这样的
但是当我选择任何片段时,所选图像不会填充整个片段并且看起来像这样
如何解决这个问题,我哪里出错了
问候兰吉特