2
This commit is contained in:
@@ -16,6 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/// 输入框
|
||||
@property (nonatomic, strong, readonly) UITextField *textField;
|
||||
|
||||
/// 背景视图圆角(默认 20),外部可自定义。
|
||||
@property (nonatomic, assign) CGFloat bgCornerRadius;
|
||||
|
||||
/// 点击键盘 return 或右侧按钮时回调
|
||||
@property (nonatomic, copy) void(^onSearch)(NSString *keyword);
|
||||
|
||||
@@ -28,4 +31,3 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@
|
||||
_bgView = [[UIView alloc] init];
|
||||
// 淡灰色背景 + 圆角
|
||||
_bgView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
|
||||
_bgView.layer.cornerRadius = 20;
|
||||
CGFloat radius = self.bgCornerRadius > 0 ? self.bgCornerRadius : 20.0;
|
||||
_bgView.layer.cornerRadius = radius;
|
||||
_bgView.layer.masksToBounds = YES;
|
||||
}
|
||||
return _bgView;
|
||||
@@ -122,4 +123,12 @@
|
||||
self.textField.placeholder = placeholder;
|
||||
}
|
||||
|
||||
- (void)setBgCornerRadius:(CGFloat)bgCornerRadius {
|
||||
_bgCornerRadius = bgCornerRadius;
|
||||
// 如果 bgView 已创建,立即更新圆角
|
||||
if (_bgView) {
|
||||
_bgView.layer.cornerRadius = bgCornerRadius;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user