This is the code causing you trouble:
if([label isEqual:@"0"] && component == 1) {
labelView.textColor = [UIColor grayColor];
}
You're problem is that, since the rows are getting reused, when you set one row to grey, the it goes off the stack, it will come back sometime. When it does come back, it's label color will still be grey.
So, the code should be changed to be like this:
if([label isEqual:@"0"] && component == 1) {
labelView.textColor = [UIColor grayColor];
} else
{
labelView.textColor = [UIColor blackColor]; // Or whatever color it normally is.
}
For your question about making it circular, you would set the number of rows to some crazy number like 10000
(something the user will never ever scroll through). Then set the picker's position to the middle of the 10K. You will then need to have an array that has all the values you want to display in your 'never-ending' picker.
You will then use the modulus operator (%
) to check for the remainder of dividing your array's count
by the current row. For example:
-(UIView *)somePickerWantsViewForRow:(int)row
{
...
NSString *titleForRow = [self.someArray objectAtIndex:(self.someArray.count % row)];
pickerRow.titleLabel.text = titleForRow;
}
In this example, the someArray
might be ('cat','dog','farmer','pizza')
.