2014-02-11 65 views
0

我有一個帶有兩個分段控件的項目。他們都工作到iOS7.0。現在一個沒有。我已閱讀tintColor的問題,但我認爲這是不同的。iOS 7中的UISegmentedControl

這兩個控件都使用UIImages作爲段。其中之一,圖像都顯示正確。另一方面,我得到所有藍色圖像。

我做錯了什麼或者這是一個錯誤?

這裏的故障段的代碼:

UISegmentedControl *colorControl = [[UISegmentedControl alloc] initWithItems: 
    [NSArray arrayWithObjects: 
    [UIImage imageNamed:@"White.png"], 
    [UIImage imageNamed:@"Red.png"], 
    [UIImage imageNamed:@"Yellow.png"], 
    [UIImage imageNamed:@"Green.png"], 
    [UIImage imageNamed:@"Blue.png"], 
    [UIImage imageNamed:@"Purple.png"], 
    [UIImage imageNamed:@"Black.png"], nil]]; 



    CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, rect.size.width - (kLeftMargin + kRightMargin), kPaletteHeight); 
    colorControl.frame = frame; 

    // Add DoubleTap Color capability 

    gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showMoreColors:)]; 
    [gesture setNumberOfTapsRequired:2]; 

    [colorControl addGestureRecognizer:gesture]; 

    // When the user chooses a color, the method changeColor: is called. 
    [colorControl addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventValueChanged]; 

    // Make sure the color of the color complements the black background 
    //colorControl.tintColor = [UIColor clearColor]; 

    // Add the control to the window 
    [self.view addSubview:colorControl]; 

雖然圖像都是藍色,段正常工作。

回答

0

感謝this question,我制定瞭如下修正:

-(void) buildColorBar { 
    //NSLog(@"%s", __FUNCTION__); 

    UIImage *whiteImage = [UIImage imageNamed:@"White.png"]; 
    UIImage *blackImage = [UIImage imageNamed:@"Black.png"]; 
    UIImage *purpleImage = [UIImage imageNamed:@"Purple.png"]; 
    UIImage *redImage = [UIImage imageNamed:@"Red.png"]; 
    UIImage *blueImage = [UIImage imageNamed:@"Blue.png"]; 
    UIImage *greenImage = [UIImage imageNamed:@"Green.png"]; 
    UIImage *yellowImage = [UIImage imageNamed:@"Yellow.png"]; 

    NSArray *colorArray = [[NSArray alloc] initWithObjects: 
        [whiteImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal], 
        [redImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], 
        [yellowImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], 
        [greenImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], 
        [blueImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], 
        [purpleImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], 
        [blackImage imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal ], nil ]; 


    UISegmentedControl *colorControl = [[UISegmentedControl alloc] initWithItems:colorArray]; 

    CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, rect.size.width - (kLeftMargin + kRightMargin), kPaletteHeight); 
    colorControl.frame = frame; 

我希望它可以幫助別人。