gpt4 book ai didi

ios - UIPickerView 居中列

转载 作者:行者123 更新时间:2023-11-28 19:51:23 24 4
gpt4 key购买 nike

我正在创建一个自定义时间选择器,使用 this问题作为指导,我的专栏不一致。

enter image description here

这是我创建小时和分钟标签的地方:

UILabel *hourLabel = [[UILabel alloc] initWithFrame:CGRectMake(datePickerCell.pickerView.frame.size.width/2 - 25, datePickerCell.pickerView.frame.size.height / 2 - 15, 50, 30)];
hourLabel.text = @"hour";
[datePickerCell.pickerView addSubview:hourLabel];

UILabel *minsLabel = [[UILabel alloc] initWithFrame:CGRectMake(datePickerCell.pickerView.frame.size.width - 25, datePickerCell.pickerView.frame.size.height / 2 - 15, 50, 30)];
minsLabel.text = @"min";
[datePickerCell.pickerView addSubview:minsLabel];

这是我的 viewForRow:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *columnView = [[UILabel alloc] initWithFrame:CGRectMake(pickerView.frame.size.width/4 - 15, 0, 35, 30)];
columnView.text = [NSString stringWithFormat:@"%lu", row];
columnView.textAlignment = NSTextAlignmentRight;

return columnView;
}

如何让 0 与底部数字对齐?

最佳答案

尝试实现以下委托(delegate)方法:

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component

将宽度减少到您需要的最小空间,它们应该排列得更好,因为这可以防止文本向左或向右移动。还可以尝试将文本居中放置在 1 到 2 个字符之间,以强制内容保持一致。

关于ios - UIPickerView 居中列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29038901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com