IOS - UISegmentationControl为IOS6和IOS7设置图像

时间:2013-10-16 08:38:17

标签: iphone ios objective-c uisegmentedcontrol

这里我使用了UISegmentationControl,我需要设置图像进行分割。在ios7中,图像放置在正确的位置,但在ios6和早期版本中,图像尺寸不正确,请参阅附图

在IOS6中,图像显示错误的图像

IOS6 在IOS7中,图像的方式是正确的

IOS7

代码我用来将图像设置为

UIImage *separator;
UIImage *onstate;
UIImage *offstate;
UIImage *unselected_right_state;
UIImage *unselected_left_state;

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
    separator = [[UIImage imageNamed:@"gseprator.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    onstate = [[UIImage imageNamed:@"on.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    offstate = [[UIImage imageNamed:@"off.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    unselected_right_state = [[UIImage imageNamed:@"gon2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    unselected_left_state = [[UIImage imageNamed:@"goff1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
else {
    separator = [UIImage imageNamed:@"gseprator.png"];
    onstate = [UIImage imageNamed:@"on.png"];
    offstate = [UIImage imageNamed:@"off.png"];
    unselected_right_state = [UIImage imageNamed:@"gon2.png"];
    unselected_left_state = [UIImage imageNamed:@"goff1.png"];
}

    if (true) {
        [[cell onoffSegment] setImage:onstate forSegmentAtIndex:0];
        [[cell onoffSegment] setImage:unselected_right_state forSegmentAtIndex:1];
    }else{
        [[cell onoffSegment] setImage:unselected_left_state forSegmentAtIndex:0];
        [[cell onoffSegment] setImage:offstate forSegmentAtIndex:1];
    }

0 个答案:

没有答案