-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultPageControlViewController.py
128 lines (104 loc) · 4.29 KB
/
defaultPageControlViewController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
todo:
Storyboard 未対応
各 frame が仮
`centerXAnchor` の挙動
"""
from pyrubicon.objc.api import ObjCClass
from pyrubicon.objc.api import objc_method
from pyrubicon.objc.runtime import send_super, SEL
from pyrubicon.objc.types import CGRectMake
from rbedge.enumerations import UIControlEvents
from rbedge.functions import NSStringFromClass
from pyLocalizedString import localizedString
UIViewController = ObjCClass('UIViewController')
UIView = ObjCClass('UIView')
UIPageControl = ObjCClass('UIPageControl')
UIColor = ObjCClass('UIColor')
NSLayoutConstraint = ObjCClass('NSLayoutConstraint')
colors = [
#UIColor.blackColor,
UIColor.whiteColor, # todo: Dark Mode
UIColor.systemGrayColor(),
UIColor.systemRedColor(),
UIColor.systemGreenColor(),
UIColor.systemBlueColor(),
UIColor.systemPinkColor(),
UIColor.systemYellowColor(),
UIColor.systemIndigoColor(),
UIColor.systemOrangeColor(),
UIColor.systemPurpleColor(),
]
class PageControlViewController(UIViewController):
@objc_method
def viewDidLoad(self):
send_super(__class__, self, 'viewDidLoad') # xxx: 不要?
# --- Navigation
title = NSStringFromClass(__class__)
#self.navigationItem.title = title
self.navigationItem.title = localizedString('DefaultPageControlTitle')
self.view.backgroundColor = UIColor.systemBackgroundColor()
# xxx: あとで切り出す
self.pageControl = UIPageControl.alloc().init().autorelease()
self.colorView: UIView = UIView.new()
self.setlayout()
self.configurePageControl()
self.pageControlValueDidChange()
@objc_method
def setlayout(self):
safeAreaLayoutGuide = self.view.safeAreaLayoutGuide
# xxx: 仮置き
self.pageControl.frame = CGRectMake(16.0, 639.5, 343.0, 27.5)
self.colorView.frame = CGRectMake(40.0, 79.0, 295.0, 548.0)
#self.colorView.backgroundColor = UIColor.systemMintColor()
self.view.addSubview_(self.pageControl)
self.view.addSubview_(self.colorView)
# --- layout
self.pageControl.translatesAutoresizingMaskIntoConstraints = False
NSLayoutConstraint.activateConstraints_([
self.pageControl.trailingAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.trailingAnchor, -40),
self.pageControl.leadingAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.leadingAnchor, 40),
self.pageControl.bottomAnchor.constraintEqualToAnchor_(
safeAreaLayoutGuide.bottomAnchor),
])
self.colorView.translatesAutoresizingMaskIntoConstraints = False
NSLayoutConstraint.activateConstraints_([
self.colorView.trailingAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.trailingAnchor, -40),
self.colorView.leadingAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.leadingAnchor, 40),
self.colorView.topAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.topAnchor, 35),
self.colorView.bottomAnchor.constraintEqualToAnchor_constant_(
safeAreaLayoutGuide.bottomAnchor, -40),
])
@objc_method
def configurePageControl(self):
# wip: よしなに要素を配置したい
self.pageControl.setNumberOfPages_(len(colors))
self.pageControl.setCurrentPage_(2)
self.pageControl.setPageIndicatorTintColor_(UIColor.systemGreenColor())
self.pageControl.setCurrentPageIndicatorTintColor_(
UIColor.systemPurpleColor())
# xxx: 要素範囲確認用
#self.pageControl.setBackgroundColor_(UIColor.systemDarkRedColor())
self.pageControl.addTarget_action_forControlEvents_(
self, SEL('pageControlValueDidChange'), UIControlEvents.valueChanged)
# MARK: - Actions
@objc_method
def pageControlValueDidChange(self):
# The total number of available pages is based on the number of available colors.
# 利用可能なページの総数は、利用可能な色の数に基づいています。
print(
f'The page control changed its current page to {self.pageControl.currentPage}.'
)
self.colorView.backgroundColor = colors[self.pageControl.currentPage]
if __name__ == '__main__':
from rbedge.enumerations import UIModalPresentationStyle
from rbedge import present_viewController
from rbedge import pdbr
pc_vc = PageControlViewController.new()
style = UIModalPresentationStyle.fullScreen
present_viewController(pc_vc, style)