我正在尝试创建一个 UIPicker,我可以在其中选择分钟和秒。这是代码:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component == 0)
return 24;
return 60;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 30;
}
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
[paragraphStyle setTailIndent:20];
NSString *value = [NSString stringWithFormat:@"%d", row];
return [[NSAttributedString alloc] initWithString:value
attributes:@{NSParagraphStyleAttributeName:paragraphStyle}];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
return 160;
}
我怎样才能摆脱烦人的曲率,只做垂直的柱子?
另外,如何在选择行中添加“min”和“sec”?