1

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

在 IOS6 中,图像显示错误

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

IOS 7

我用来将图像设置为的代码

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

0 回答 0