gpt4 book ai didi

ios - UIPickerView 设置选定行的背景颜色(现在也适用于 iOS 14)

转载 作者:行者123 更新时间:2023-12-04 12:51:34 44 4
gpt4 key购买 nike

我找到了这个代码 here :

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = (UILabel*) view;
if (label == nil)
{
label = [[UILabel alloc] init];
}

[label setText:@"Whatever"];

// This part just colorizes everything, since you asked about that.

[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor blackColor]];
CGSize rowSize = [pickerView rowSizeForComponent:component];
CGRect labelRect = CGRectMake (0, 0, rowSize.width, rowSize.height);
[label setFrame:labelRect];

return label;
}

但是,正如评论中所述,它有一个问题:

It colorizes the labels, but not the picker, itself. So, when you roll to one end or the other, there's a blank spot where you can see the white background.



我只需要更改所选行的背景颜色。

最佳答案

我发现在 iOS 14 中,我现在在选择器的选定项目上获得了灰色背景颜色。目前的要求是摆脱它。
所以这似乎有效。

pickerView.subviews[safe:1]?.backgroundColor = UIColor.clear 
(“safe”是一个执行数组边界检查并在索引无效时返回 nil 的运算符)
我从这里得到了这个想法: https://stackoverflow.com/a/53740571/826946

关于ios - UIPickerView 设置选定行的背景颜色(现在也适用于 iOS 14),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493944/

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