【问题标题】:UISegmentedControl in iOS 7iOS 7 中的 UISegmentedControl
【发布时间】:2014-02-12 11:14:53
【问题描述】:

我有一个包含两个分段控件的项目。他们都工作到了iOS7.0。现在一个没有。我读过有关 tintColor 的问题,但我认为这是不同的。

两个控件都使用 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];

虽然图像都是蓝色的,但片段按预期工作。

【问题讨论】:

    标签: ios7 uisegmentedcontrol


    【解决方案1】:

    感谢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;
    

    我希望它可以帮助别人。

    【讨论】:

      猜你喜欢
      • 2014-03-20
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      相关资源
      最近更新 更多