ios - 2 行(多行)长文本选择器

标签 ios picker

为什么我可以为选择器设置行高或多行, 问题是我的选择器有很长的文本,或者在选择器中换行... xcode 5 ... 我从数组中获取选择器的值。 我的自定义选择器代码是:

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

    UILabel *label = [[UILabel alloc] init];
    CGRect frame = CGRectMake(0,0,265,40);
    label.backgroundColor = PickColor;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18 ];
    label.textAlignment = NSTextAlignmentCenter;



    if(component == 0)
    {
        label.text = [_vergehen objectAtIndex:row];
    }
        return label;
}

感谢帮助

最佳答案

试试这段代码

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
  return 50;
}

然后

- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
   UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 310, 50)];
   lblTitle.numberOfLines=2;
   lblTitle.textColor=[UIColor blackColor];
   lblTitle.font=[UIFont systemFontOfSize:14];
   lblTitle.text=[selectionList objectAtIndex:row];
   return lblTitle;
}

关于ios - 2 行(多行)长文本选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435751/

相关文章:

ios - NSObject 和 AnyObject 有什么区别?什么时候用这两个?

ios - 如何在 iOS 13 上设置 UIToolbar 高度

iphone - 文本更改后 UILabel 未正确换行

ios - 在 Swift 中将 NSMutableDictionary 转换为 NSData

c# - 将数据从主页上的 web api 传递到 xamarin 表单中的详细信息页面

swiftui - SwiftUI 中的选择器适用于一个版本的 ForEach,但不适用于另一个版本 - 错误或预期行为?

ios - 在 iOS 应用程序中实现 OAuth 1.0 (Withings api)

ios - SwiftUI 从选择器的字符串结果中设置绑定(bind)

ios - 更改 SwiftUI 中选取器的导航标题

swift - 我希望我的选择器使用新子项重新加载 Firebase 数据