2
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
// 保存按钮
|
||||
@property (nonatomic, strong) UIButton *saveButton;
|
||||
|
||||
/// 当前选中的行索引,用于控制高亮颜色(避免依赖 UIPickerView 的内部状态时机)
|
||||
@property (nonatomic, assign) NSInteger currentSelectedRow;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBGenderPickerPopView
|
||||
@@ -32,6 +35,7 @@
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.backgroundColor = UIColor.clearColor;
|
||||
self.currentSelectedRow = 0;
|
||||
// 默认三项(使用多语言文案)
|
||||
_items = @[
|
||||
@{ @"id": @"1", @"name": KBLocalized(@"Male") },
|
||||
@@ -67,6 +71,7 @@
|
||||
if (idx != NSNotFound) row = (NSInteger)idx;
|
||||
}
|
||||
if (row < (NSInteger)self.items.count) {
|
||||
self.currentSelectedRow = row;
|
||||
[self.picker selectRow:row inComponent:0 animated:NO];
|
||||
}
|
||||
[self.picker reloadAllComponents];
|
||||
@@ -151,14 +156,15 @@
|
||||
}
|
||||
NSString *name = self.items[row][@"name"] ?: @"";
|
||||
label.text = name;
|
||||
BOOL selected = (row == [pickerView selectedRowInComponent:0]);
|
||||
BOOL selected = (row == self.currentSelectedRow);
|
||||
label.textColor = selected ? [UIColor colorWithRed:0.02 green:0.75 blue:0.67 alpha:1.0]
|
||||
: [UIColor colorWithWhite:0.65 alpha:1.0];
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
|
||||
// 选中变化后刷新颜色
|
||||
// 记录当前选中行并刷新颜色
|
||||
self.currentSelectedRow = row;
|
||||
[pickerView reloadAllComponents];
|
||||
}
|
||||
|
||||
@@ -216,7 +222,7 @@
|
||||
return _lineBottom;
|
||||
}
|
||||
- (UIView *)makeLine { UIView *v = [UIView new]; v.backgroundColor = [UIColor colorWithWhite:0.88 alpha:1.0]; return v; }
|
||||
|
||||
|
||||
- (UIButton *)saveButton {
|
||||
if (!_saveButton) {
|
||||
_saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/11.
|
||||
//
|
||||
|
||||
//
|
||||
// KBPersonInfoVC.m
|
||||
// 个人资料
|
||||
//
|
||||
|
||||
|
||||
Reference in New Issue
Block a user