gpt4 book ai didi

ios - 如何使 UIPickerView 组件文本始终适合?

转载 作者:行者123 更新时间:2023-12-01 17:50:52 24 4
gpt4 key购买 nike

假设您有一个 UIPickerView 并且您希望您的文本始终适合其组件获得的给定空间(没有“...”表示不合适的文本)。

如何解决这个问题?

最佳答案

简单的解决方案:

实现

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

在你的选择器代表中是这样的:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* tView = (UILabel*)view;
if (!tView)
{
tView = [[UILabel alloc] init];

tView.textAlignment = NSTextAlignmentCenter;

tView.adjustsFontSizeToFitWidth = YES;
// Setup label properties - frame, font, colors etc
}

tView.text = [self pickerView:pickerView titleForRow:row forComponent:component];
//Add any logic you want here

return tView;
}

这使得标签完美地适合其中的文本。

享受!

关于ios - 如何使 UIPickerView 组件文本始终适合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31642094/

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