gpt4 book ai didi

ios - 如何获取自定义 UIPickerView?

转载 作者:可可西里 更新时间:2023-11-01 03:30:34 25 4
gpt4 key购买 nike

我想在 Custom UIPiker 中实现以下功能,如下图所示。

enter image description here

我只想像上面那样更改选定区域的文本颜色。

最佳答案

在您的 viewDidLoad 方法中的 pickerview 中添加标签,如下所示。

ViewController.h 文件中定义 labelmyPickerView

- (void)viewDidLoad
{

myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
[self.view addSubview:myPickerView];

label = [[UILabel alloc] initWithFrame:CGRectMake(145, 76, 36, 36)];
//label.text = @"Label";
label.font = [UIFont boldSystemFontOfSize:20];
label.layer.cornerRadius = 18;
[label setTextColor:[UIColor whiteColor]];
label.backgroundColor = [UIColor blueColor];
label.textAlignment = NSTextAlignmentCenter;
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake (0,1);
[myPickerView addSubview:label];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

在 pickerview 委托(delegate)中设置标签标题。

#pragma mark - PickerView delegate

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection

[label setText:[NSString stringWithFormat:@"%d",row]];
NSLog(@"%@",[NSString stringWithFormat:@"%d",row]);

}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

NSLog(@"%@",[NSString stringWithFormat:@"%d",row]);
[label setText:[NSString stringWithFormat:@"%d",row]];
return [NSString stringWithFormat:@"%d",row];
}

您的 OuytPut 是:

enter image description here

关于ios - 如何获取自定义 UIPickerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25156986/

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