@@ -5,31 +5,108 @@ class RootViewController: UIViewController {
55 override func viewDidLoad( ) {
66 super. viewDidLoad ( )
77
8- self . title = " RootViewController "
9- // 设置背景颜色以区分
8+ self . title = NSLocalizedString ( " CFBundleDisplayName " , comment: " " )
9+
10+ // 设置ViewController的背景颜色
1011 self . view. backgroundColor = UIColor . systemBackground
11-
12- let appIcon = UIImage ( named: " AppIcon " )
13- // let imageView = UIImageView(image: appIcon)
14- let imageView = UIImageView ( )
15- imageView. image = UIImage ( systemName: " power.circle.fill " )
16- imageView. tintColor = UIColor ( hex: " #32a5e7 " )
12+
13+ // icon
14+ let iconImageView = UIImageView ( )
15+
16+ if #available( iOS 15 . 0 , * ) {
17+ iconImageView. image = UIImage ( systemName: " power.circle.fill " )
18+ iconImageView. tintColor = UIColor ( hex: " #32A5E7 " )
19+ } else {
20+ let appIcon = UIImage ( named: " AppIcon " )
21+ iconImageView. image = appIcon
22+ }
23+
1724 // 禁用自动调整大小
18- imageView . translatesAutoresizingMaskIntoConstraints = false
25+ iconImageView . translatesAutoresizingMaskIntoConstraints = false
1926 // 设置图片适应方式
20- imageView. contentMode = . scaleAspectFit
21-
22- self . view. addSubview ( imageView)
23-
24- // AutoLaout
27+ iconImageView. contentMode = . scaleAspectFit
28+
29+ // 检查权限
30+ let checkPermissionLabel = UILabel ( )
31+ checkPermissionLabel. translatesAutoresizingMaskIntoConstraints = false
32+ checkPermissionLabel. textAlignment = . center // 设置文本居中
33+
34+ var enable = self . checkInstallPermission ( )
35+
36+ if ( enable) {
37+ checkPermissionLabel. text = NSLocalizedString ( " Install_With_TrollStore_text " , comment: " " )
38+ checkPermissionLabel. textColor = UIColor . green
39+ } else {
40+ checkPermissionLabel. text = NSLocalizedString ( " Need_Install_With_TrollStore_text " , comment: " " )
41+ checkPermissionLabel. textColor = UIColor . red
42+ }
43+
44+ // 重启按钮
45+ let rebootButton = UIButton ( )
46+ rebootButton. setTitle ( NSLocalizedString ( " Reboot_Device_text " , comment: " " ) , for: . normal)
47+ rebootButton. translatesAutoresizingMaskIntoConstraints = false
48+
49+ // 添加设置项
50+ let showAlertSwitch = UISwitch ( )
51+ showAlertSwitch. translatesAutoresizingMaskIntoConstraints = false
52+
53+ let showAlertLabel = UILabel ( )
54+ showAlertLabel. text = NSLocalizedString ( " Show_Alert_Before_Starting_text " , comment: " " )
55+ showAlertLabel. textColor = UIColor . label
56+ showAlertLabel. translatesAutoresizingMaskIntoConstraints = false
57+
58+ // 添加子视图
59+ let showAlertSubView = UIView ( )
60+ showAlertSubView. translatesAutoresizingMaskIntoConstraints = false
61+ // 将开关和标签添加到子视图中
62+ showAlertSubView. addSubview ( showAlertLabel)
63+ showAlertSubView. addSubview ( showAlertSwitch)
64+
65+ // 向View中添加控件
66+ self . view. addSubview ( iconImageView)
67+ self . view. addSubview ( checkPermissionLabel)
68+ self . view. addSubview ( rebootButton)
69+ self . view. addSubview ( showAlertSubView)
70+
71+
72+ // AutoLayout
2573 NSLayoutConstraint . activate ( [
26- imageView. widthAnchor. constraint ( equalToConstant: 100 ) , // 设置宽度
27- imageView. heightAnchor. constraint ( equalToConstant: 100 ) , // 设置高度
28- imageView. centerXAnchor. constraint ( equalTo: self . view. centerXAnchor) , // 水平居中
29- imageView. topAnchor. constraint ( equalTo: self . view. topAnchor, constant: 100 )
30-
74+ iconImageView. widthAnchor. constraint ( equalToConstant: 100 ) , // 设置宽度
75+ iconImageView. heightAnchor. constraint ( equalToConstant: 100 ) , // 设置高度
76+ iconImageView. centerXAnchor. constraint ( equalTo: self . view. centerXAnchor) , // 水平居中
77+ iconImageView. topAnchor. constraint ( equalTo: self . view. topAnchor, constant: 100 ) ,
78+
79+ checkPermissionLabel. centerXAnchor. constraint ( equalTo: self . view. centerXAnchor) , // 水平居中
80+ checkPermissionLabel. topAnchor. constraint ( equalTo: iconImageView. bottomAnchor, constant: 30 ) , // 在 iconImageView 底部,间隔 20 点
81+ checkPermissionLabel. leadingAnchor. constraint ( equalTo: self . view. leadingAnchor, constant: 20 ) , // 左侧边距
82+ checkPermissionLabel. trailingAnchor. constraint ( equalTo: self . view. trailingAnchor, constant: - 20 ) , // 右侧边距
83+
84+ rebootButton. centerXAnchor. constraint ( equalTo: self . view. centerXAnchor) , // 水平居中
85+ rebootButton. topAnchor. constraint ( equalTo: checkPermissionLabel. bottomAnchor, constant: 30 ) ,
86+ rebootButton. leadingAnchor. constraint ( equalTo: self . view. leadingAnchor, constant: 20 ) , // 左侧边距
87+ rebootButton. trailingAnchor. constraint ( equalTo: self . view. trailingAnchor, constant: - 20 ) , // 右侧边距
88+
89+ showAlertSubView. centerXAnchor. constraint ( equalTo: self . view. centerXAnchor) ,
90+ showAlertSubView. topAnchor. constraint ( equalTo: rebootButton. bottomAnchor, constant: 30 ) ,
91+ // 动态设置容器的宽度和高度
92+ showAlertSubView. leadingAnchor. constraint ( equalTo: showAlertLabel. leadingAnchor) ,
93+ showAlertSubView. trailingAnchor. constraint ( equalTo: showAlertSwitch. trailingAnchor) ,
94+ showAlertSubView. heightAnchor. constraint ( equalTo: showAlertSwitch. heightAnchor) ,
95+ // 标签和开关在容器中水平排列
96+ showAlertLabel. leadingAnchor. constraint ( equalTo: showAlertSubView. leadingAnchor) ,
97+ showAlertLabel. centerYAnchor. constraint ( equalTo: showAlertSubView. centerYAnchor) ,
98+
99+ showAlertSwitch. leadingAnchor. constraint ( equalTo: showAlertLabel. trailingAnchor, constant: 10 ) ,
100+ showAlertSwitch. centerYAnchor. constraint ( equalTo: showAlertSubView. centerYAnchor) ,
101+ showAlertSwitch. trailingAnchor. constraint ( equalTo: showAlertSubView. trailingAnchor)
31102 ] )
32103 }
104+
105+ func checkInstallPermission( ) -> Bool {
106+ let path = " /var/mobile/Library/Preferences "
107+ let writeable = access ( path, W_OK) == 0
108+ return writeable
109+ }
33110}
34111
35112extension UIColor {
0 commit comments