108 lines
3.5 KiB
Objective-C
108 lines
3.5 KiB
Objective-C
#import "KBNoticeVC.h"
|
|
#import <Masonry/Masonry.h>
|
|
|
|
@interface KBNoticeVC ()
|
|
/// 顶部白色卡片容器
|
|
@property (nonatomic, strong) UIView *cardView;
|
|
/// “Notification Setting” 标题
|
|
@property (nonatomic, strong) UILabel *noticeTitleLabel;
|
|
/// 通知开关
|
|
@property (nonatomic, strong) UISwitch *noticeSwitch;
|
|
|
|
@end
|
|
|
|
@implementation KBNoticeVC
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// 背景色与设置页风格保持一致
|
|
self.view.backgroundColor = [UIColor colorWithHex:0xF8F8F8];
|
|
// 导航标题
|
|
self.kb_titleLabel.text = KBLocalized(@"Notice");
|
|
|
|
// 添加子视图
|
|
[self.view addSubview:self.cardView];
|
|
[self.cardView addSubview:self.noticeTitleLabel];
|
|
[self.cardView addSubview:self.noticeSwitch];
|
|
|
|
// 布局:卡片
|
|
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// 顶部距离自定义导航栏一定间距
|
|
make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT + 16);
|
|
make.left.equalTo(self.view).offset(16);
|
|
make.right.equalTo(self.view).offset(-16);
|
|
make.height.mas_equalTo(64);
|
|
}];
|
|
|
|
// 布局:标题
|
|
[self.noticeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.cardView).offset(20);
|
|
make.centerY.equalTo(self.cardView);
|
|
}];
|
|
|
|
// 布局:开关
|
|
[self.noticeSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self.cardView).offset(-20);
|
|
make.centerY.equalTo(self.cardView);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Actions
|
|
|
|
/// 通知开关值变化回调(后续在此方法内实现具体业务)
|
|
- (void)noticeSwitchChanged:(UISwitch *)sender {
|
|
BOOL isOn = sender.isOn;
|
|
// TODO: 根据 isOn 处理通知开关逻辑(例如本地存储、上报等)
|
|
}
|
|
|
|
#pragma mark - Lazy Load
|
|
|
|
- (UIView *)cardView {
|
|
if (!_cardView) {
|
|
_cardView = [UIView new];
|
|
_cardView.backgroundColor = [UIColor whiteColor];
|
|
_cardView.layer.cornerRadius = 16.0;
|
|
_cardView.layer.masksToBounds = NO;
|
|
// 阴影效果,接近设计稿
|
|
_cardView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.06].CGColor;
|
|
_cardView.layer.shadowOpacity = 1.0;
|
|
_cardView.layer.shadowOffset = CGSizeMake(0, 4);
|
|
_cardView.layer.shadowRadius = 8.0;
|
|
}
|
|
return _cardView;
|
|
}
|
|
|
|
- (UILabel *)noticeTitleLabel {
|
|
if (!_noticeTitleLabel) {
|
|
_noticeTitleLabel = [UILabel new];
|
|
_noticeTitleLabel.textColor = [UIColor colorWithHex:KBBlackValue];
|
|
_noticeTitleLabel.font = [KBFont medium:16];
|
|
// 文案可根据需要在 Localizable.strings 中配置多语言
|
|
_noticeTitleLabel.text = KBLocalized(@"Notification Setting");
|
|
}
|
|
return _noticeTitleLabel;
|
|
}
|
|
|
|
- (UISwitch *)noticeSwitch {
|
|
if (!_noticeSwitch) {
|
|
_noticeSwitch = [[UISwitch alloc] init];
|
|
_noticeSwitch.on = YES;
|
|
// 自定义开关主色(可根据设计调整)
|
|
if (@available(iOS 13.0, *)) {
|
|
_noticeSwitch.onTintColor = [UIColor systemGreenColor];
|
|
} else {
|
|
_noticeSwitch.onTintColor = [UIColor colorWithRed:76/255.0
|
|
green:217/255.0
|
|
blue:100/255.0
|
|
alpha:1.0];
|
|
}
|
|
// 监听值变化
|
|
[_noticeSwitch addTarget:self
|
|
action:@selector(noticeSwitchChanged:)
|
|
forControlEvents:UIControlEventValueChanged];
|
|
}
|
|
return _noticeSwitch;
|
|
}
|
|
|
|
@end
|