Skip to content

Commit cabc864

Browse files
author
DevelopLab
committed
1.Finished layout design
2.Add some accessibility label
1 parent ab87421 commit cabc864

4 files changed

Lines changed: 70 additions & 19 deletions

File tree

Resources/en.lproj/Localizable.strings

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Respring_text" = "Respring";
66
"Settings_text" = "Settings";
77
"Done_text" = "Done";
8+
"Cancel_text" = "Cancel";
89
"General_text" = "General";
910
"Timer_text" = "Timer";
1011
"About_text" = "About";
@@ -13,7 +14,11 @@
1314
"Display_Root_Permission_text" = "Show root permission has been obtained text";
1415
"Enable_text" = "Enable";
1516
"Time_text" = "Time";
17+
"Seconds_text" = "%d seconds";
1618
"Action_text" = "Action";
19+
"Choose_An_Action_text" = "Choose an action";
20+
"When_Open_Application_To_Action_text" = "Automatically perform operations when launching the Application";
1721
"Show_Alert_Before_Starting_text" = "Show alert before starting";
1822
"Version_text" = "Version";
19-
"Unknown_text" = "Unknown";
23+
"Unknown_text" = "Unknown";
24+
"Special_Thanks_text" = "Special thanks to Xiaobovlog\nProvides core code for reboot";

Resources/zh-Hans.lproj/Localizable.strings

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
"Respring_text" = "注销";
66
"Settings_text" = "设置";
77
"Done_text" = "完成";
8+
"Cancel_text" = "取消";
89
"General_text" = "通用";
9-
"Timer_text" = "计时器";
10+
"Timer_text" = "倒计时器";
1011
"About_text" = "关于";
1112
"Enable_Function_text" = "启用的功能";
12-
"Home_Screen_Quick_Actions_text" = "图标快捷方式";
13+
"Home_Screen_Quick_Actions_text" = "桌面图标快捷方式";
1314
"Display_Root_Permission_text" = "显示已获得Root授权提示";
1415
"Enable_text" = "启用";
1516
"Time_text" = "时间";
17+
"Seconds_text" = "%d 秒";
1618
"Action_text" = "执行的操作";
19+
"Choose_An_Action_text" = "选择一个操作";
20+
"When_Open_Application_To_Action_text" = "启动App时自动进行操作";
1721
"Show_Alert_Before_Starting_text" = "开始操作前显示提醒";
1822
"Version_text" = "版本";
19-
"Unknown_text" = "未知";
23+
"Unknown_text" = "未知";
24+
"Special_Thanks_text" = "特别感谢肖博vlog\n提供重启设备核心代码";

RootViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class RootViewController: UIViewController {
2020
let appIcon = UIImage(named: "AppIcon")
2121
iconImageView.image = appIcon
2222
}
23+
// 无障碍标签
24+
iconImageView.isAccessibilityElement = true // 声明这是一个可访问性元素
25+
iconImageView.accessibilityLabel = NSLocalizedString("CFBundleDisplayName", comment: "")
2326

2427
// 禁用自动调整大小
2528
iconImageView.translatesAutoresizingMaskIntoConstraints = false

SettingsViewController.swift

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import UIKit
33
class SettingsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
44

55
let tableView = UITableView(frame: .zero, style: .insetGrouped)
6+
let options = [NSLocalizedString("Reboot_Device_text", comment: ""), NSLocalizedString("Respring_text", comment: "")]
7+
var selectedOption: String = NSLocalizedString("Reboot_Device_text", comment: "") // 默认选项
68

79
// 每个分组的小标题
810
let sectionTitles = [
@@ -16,9 +18,9 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
1618
let sections = [
1719
[NSLocalizedString("Show_Alert_Before_Starting_text", comment: ""), NSLocalizedString("Display_Root_Permission_text", comment: "")],
1820
[NSLocalizedString("Respring_text", comment: ""), NSLocalizedString("Home_Screen_Quick_Actions_text", comment: "")],
19-
[NSLocalizedString("Enable_text", comment: ""), NSLocalizedString("Time_text", comment: ""), NSLocalizedString("Action_text", comment: "")],
21+
[NSLocalizedString("Enable_text", comment: ""), NSLocalizedString("Time_text", comment: ""), NSLocalizedString("Action_text", comment: ""), NSLocalizedString("When_Open_Application_To_Action_text", comment: "")],
2022
// [String(localized: "Version_text"),"Github"]
21-
[NSLocalizedString("Version_text", comment: ""),"Github"]
23+
[NSLocalizedString("Version_text", comment: ""),"GitHub", NSLocalizedString("Special_Thanks_text", comment: "")]
2224
]
2325

2426
// UserDefaults 键
@@ -66,14 +68,14 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
6668
// 设置单元格的文本
6769
cell.textLabel?.text = sections[indexPath.section][indexPath.row]
6870
cell.textLabel?.numberOfLines = 0 // 允许文本过长时换行
71+
cell.selectionStyle = .none // 禁用选中效果
6972

7073
switch indexPath.section {
7174
case 0, 1:
7275
// 创建 UISwitch 控件
7376
let switchView = UISwitch(frame: .zero)
7477
switchView.tag = indexPath.section
7578
switchView.addTarget(self, action: #selector(self.switchChanged(_:)), for: .valueChanged)
76-
7779
// 根据不同的设置项初始化开关状态
7880
if indexPath.section == 0 {
7981
switchView.isOn = UserDefaults.standard.bool(forKey: self.warningKey)
@@ -85,7 +87,7 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
8587

8688
cell.accessoryView = switchView
8789
case 2: // 倒计时器的设置
88-
if indexPath.row == 0 { // Enable
90+
if indexPath.row == 0 || indexPath.row == 3 { // Enable
8991
let switchView = UISwitch(frame: .zero)
9092
switchView.tag = indexPath.section
9193
switchView.addTarget(self, action: #selector(self.switchChanged(_:)), for: .valueChanged)
@@ -95,22 +97,22 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
9597
// 添加 UIStepper
9698
cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
9799
cell.textLabel?.text = sections[indexPath.section][indexPath.row]
98-
cell.detailTextLabel?.text = "1秒" // 默认值
100+
cell.detailTextLabel?.text = String.localizedStringWithFormat(NSLocalizedString("Seconds_text", comment: "Time in seconds"), 5) // 默认值
99101
let stepper = UIStepper()
100102
stepper.minimumValue = 0 // 最小值
101103
stepper.maximumValue = 15 // 最大值
102-
stepper.value = 1 // 初始值
104+
stepper.value = 5 // 初始值
103105
stepper.stepValue = 1 // 每次加减步长
104-
105106
// 添加事件监听
106107
stepper.addTarget(self, action: #selector(self.stepperValueChanged(_:)), for: .valueChanged)
107108

108109
// 设置 UIStepper 为 cell 的 accessoryView
109110
cell.accessoryView = stepper
110111
} else if indexPath.row == 2 {
111-
//
112-
113-
112+
cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
113+
cell.textLabel?.text = sections[indexPath.section][indexPath.row]
114+
cell.detailTextLabel?.text = selectedOption // 显示当前选中的选项
115+
cell.accessoryType = .disclosureIndicator // 添加右侧箭头
114116
}
115117
case 3:
116118
if indexPath.row == 0 {
@@ -120,9 +122,11 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
120122
cell.detailTextLabel?.text = version
121123
cell.selectionStyle = .none
122124
cell.accessoryType = .none
125+
} else if indexPath.row == 1 || indexPath.row == 2 {
126+
cell.accessoryType = .disclosureIndicator
127+
cell.selectionStyle = .default // 启用选中效果
123128
}
124129

125-
126130
default: break
127131

128132
}
@@ -131,7 +135,6 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
131135
}
132136

133137
// MARK: - UISwitch 事件处理
134-
135138
@objc func switchChanged(_ sender: UISwitch) {
136139
if sender.tag == 0 {
137140
// 第一个设置项:执行操作前发出警告
@@ -147,13 +150,48 @@ class SettingsViewController: UIViewController, UITableViewDelegate, UITableView
147150
// 找到 UIStepper 所在的单元格
148151
if let cell = sender.superview as? UITableViewCell {
149152
// 更新 detailTextLabel 显示当前值
150-
cell.detailTextLabel?.text = "\(Int(sender.value))"
153+
cell.detailTextLabel?.text = String.localizedStringWithFormat(NSLocalizedString("Seconds_text", comment: ""), Int(sender.value))
151154
}
152155
}
153156

154-
// MARK: - UITableViewDelegate
157+
// MARK: - UITableViewDelegate 点击item的事件
155158
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
156-
tableView.deselectRow(at: indexPath, animated: true)
159+
if indexPath.section == 2 && indexPath.row == 2 {
160+
let actionSheet = UIAlertController(title: NSLocalizedString("Choose_An_Action_text", comment: ""), message: nil, preferredStyle: .actionSheet)
161+
162+
// 添加选项
163+
for option in options {
164+
let action = UIAlertAction(title: option, style: .default) { _ in
165+
self.selectedOption = option
166+
tableView.reloadRows(at: [indexPath], with: .none) // 更新单元格显示
167+
}
168+
actionSheet.addAction(action)
169+
}
170+
171+
// 添加取消按钮
172+
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel_text", comment: ""), style: .cancel, handler: nil)
173+
actionSheet.addAction(cancelAction)
174+
175+
// 显示弹窗
176+
if let popover = actionSheet.popoverPresentationController {
177+
// 处理 iPad 的情况
178+
popover.sourceView = tableView
179+
popover.sourceRect = tableView.rectForRow(at: indexPath)
180+
popover.permittedArrowDirections = .any
181+
}
182+
183+
present(actionSheet, animated: true, completion: nil)
184+
} else if indexPath.section == 3 && indexPath.row == 1 {
185+
tableView.deselectRow(at: indexPath, animated: true)
186+
if let url = URL(string: "https://github.com/DevelopCubeLab/RebootTools") {
187+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
188+
}
189+
} else if indexPath.section == 3 && indexPath.row == 2 {
190+
tableView.deselectRow(at: indexPath, animated: true)
191+
if let url = URL(string: "https://m.xiaobovlog.cn/") {
192+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
193+
}
194+
}
157195
}
158196

159197
// MARK: - 设置每个分组的标题

0 commit comments

Comments
 (0)