开发者

Any Way To Display 1/2 Instead of .5 In UIPickerView?

开发者 https://www.devze.com 2023-02-27 04:17 出处:网络
Is it possible to display 1/2 instead of a .5 in UI PickerView? This is the code i am currently using:

Is it possible to display 1/2 instead of a .5 in UI PickerView?

This is the code i am currently using:

开发者_StackOverflow中文版pickerArray = [[NSMutableArray alloc] initWithCapacity:700];
for ( float i = 0.0 ; i <= 1000.0 ; i = i + 2.5)
{
    //[pickerArray addObject:[NSString stringWithFormat:@"%.1f", i]]
    [pickerArray addObject:[NSNumber numberWithFloat:i];
}

float weight = [[pickerArray objectAtIndex:row] floatValue];
label.text = [NSString stringWithFormat:@"%.1f", weight];


I recommend doing something like this:

NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0;i<100;i++) {
    float value = (float)i*2.5;
    if (i % 2) {
        [array addObject:[NSString stringWithFormat:@"%d %@",(int)value,@"1/2"]];
    } else {
        [array addObject:[NSString stringWithFormat:@"%d",(int)value]];
    }
}

The array contains:

"0", "2 1/2", "5", "7 1/2", "10", "12 1/2", "15", "17 1/2", "20", "22 1/2", "25", "27 1/2", "30", "32 1/2", "35", "37 1/2", "40", and more

Update the label like this:

label.text = [array objectAtIndex:row];
0

精彩评论

暂无评论...
验证码 换一张
取 消