Skip to content

Commit 13fb982

Browse files
committed
new iOS 14 features for page control, date picker, segmented control, and buttons
1 parent 245c74e commit 13fb982

File tree

34 files changed

+1663
-60
lines changed

34 files changed

+1663
-60
lines changed

bk2ch07p372paging/ch20p676paging.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
320FE94D1B83B6AA00EEAB01 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 320FE94C1B83B6AA00EEAB01 /* LaunchScreen.storyboard */; };
1111
320FE94F1B83B6BB00EEAB01 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 320FE94E1B83B6BB00EEAB01 /* AppDelegate.swift */; };
1212
32C41057197D8D9A00D7CE24 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C41056197D8D9A00D7CE24 /* ViewController.swift */; };
13+
812A656624DD87C600C0B8F5 /* trash.png in Resources */ = {isa = PBXBuildFile; fileRef = 812A656524DD87C600C0B8F5 /* trash.png */; };
1314
C9EA927717DF5DCE00C71EDE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9EA927517DF5DCE00C71EDE /* Main.storyboard */; };
1415
C9EA927C17DF5DCE00C71EDE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9EA927B17DF5DCE00C71EDE /* Assets.xcassets */; };
1516
/* End PBXBuildFile section */
@@ -18,6 +19,7 @@
1819
320FE94C1B83B6AA00EEAB01 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
1920
320FE94E1B83B6BB00EEAB01 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2021
32C41056197D8D9A00D7CE24 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
22+
812A656524DD87C600C0B8F5 /* trash.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = trash.png; sourceTree = "<group>"; };
2123
C9EA926017DF5DCE00C71EDE /* ch20p676paging.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ch20p676paging.app; sourceTree = BUILT_PRODUCTS_DIR; };
2224
C9EA926B17DF5DCE00C71EDE /* ch20p676paging-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ch20p676paging-Info.plist"; sourceTree = "<group>"; };
2325
C9EA927617DF5DCE00C71EDE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -57,6 +59,7 @@
5759
C9EA927517DF5DCE00C71EDE /* Main.storyboard */,
5860
32C41056197D8D9A00D7CE24 /* ViewController.swift */,
5961
320FE94E1B83B6BB00EEAB01 /* AppDelegate.swift */,
62+
812A656524DD87C600C0B8F5 /* trash.png */,
6063
C9EA927B17DF5DCE00C71EDE /* Assets.xcassets */,
6164
320FE94C1B83B6AA00EEAB01 /* LaunchScreen.storyboard */,
6265
C9EA926B17DF5DCE00C71EDE /* ch20p676paging-Info.plist */,
@@ -125,6 +128,7 @@
125128
files = (
126129
320FE94D1B83B6AA00EEAB01 /* LaunchScreen.storyboard in Resources */,
127130
C9EA927C17DF5DCE00C71EDE /* Assets.xcassets in Resources */,
131+
812A656624DD87C600C0B8F5 /* trash.png in Resources */,
128132
C9EA927717DF5DCE00C71EDE /* Main.storyboard in Resources */,
129133
);
130134
runOnlyForDeploymentPostprocessing = 0;

bk2ch07p372paging/ch20p676paging/Base.lproj/Main.storyboard

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14092" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17147" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
7-
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14081.1"/>
9-
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17120"/>
106
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
117
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
128
</dependencies>
@@ -19,7 +15,7 @@
1915
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2016
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2117
<subviews>
22-
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zP0-h3-1W8">
18+
<scrollView verifyAmbiguity="off" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zP0-h3-1W8">
2319
<rect key="frame" x="16" y="66" width="343" height="155"/>
2420
<constraints>
2521
<constraint firstAttribute="height" constant="155" id="DYf-Pc-Hoc"/>
@@ -29,14 +25,13 @@
2925
</connections>
3026
</scrollView>
3127
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="dbX-zv-7S5">
32-
<rect key="frame" x="0.0" y="229" width="375" height="37"/>
33-
<color key="pageIndicatorTintColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
34-
<color key="currentPageIndicatorTintColor" red="1" green="0.21931261690000001" blue="0.45882864099999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
28+
<rect key="frame" x="0.0" y="209" width="375" height="27.5"/>
3529
<connections>
3630
<action selector="userDidPage:" destination="vXZ-lx-hvc" eventType="valueChanged" id="BCh-sE-Eod"/>
3731
</connections>
3832
</pageControl>
3933
</subviews>
34+
<viewLayoutGuide key="safeArea" id="FlY-Yj-38l"/>
4035
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4136
<constraints>
4237
<constraint firstItem="dbX-zv-7S5" firstAttribute="leading" secondItem="FlY-Yj-38l" secondAttribute="leading" id="3mf-4l-2b8"/>
@@ -46,7 +41,6 @@
4641
<constraint firstItem="zP0-h3-1W8" firstAttribute="top" secondItem="FlY-Yj-38l" secondAttribute="top" constant="46" id="iob-ME-wuQ"/>
4742
<constraint firstItem="FlY-Yj-38l" firstAttribute="trailing" secondItem="dbX-zv-7S5" secondAttribute="trailing" id="sht-0v-XRR"/>
4843
</constraints>
49-
<viewLayoutGuide key="safeArea" id="FlY-Yj-38l"/>
5044
</view>
5145
<connections>
5246
<outlet property="pager" destination="dbX-zv-7S5" id="cb2-wH-kYf"/>

bk2ch07p372paging/ch20p676paging/ViewController.swift

+19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ class ViewController : UIViewController, UIScrollViewDelegate {
2929
@IBOutlet var sv : UIScrollView!
3030
@IBOutlet var pager : UIPageControl!
3131

32+
override func viewDidLoad() {
33+
super.viewDidLoad()
34+
self.pager.currentPageIndicatorTintColor = .systemRed
35+
self.pager.pageIndicatorTintColor = .systemOrange
36+
37+
38+
// self.pager.backgroundColor = .blue
39+
// self.pager.backgroundStyle = .prominent
40+
// self.pager.pageIndicatorTintColor = .yellow
41+
// self.pager.currentPageIndicatorTintColor = .orange
42+
// self.pager.tintColor = .green // does nothing
43+
// self.pager.allowsContinuousInteraction = false
44+
// self.pager.preferredIndicatorImage = UIImage(systemName: "diamond.fill")!
45+
// self.pager.setIndicatorImage(UIImage(named: "trash")!.withRenderingMode(.alwaysOriginal), forPage: 0)
46+
// self.pager.numberOfPages = 20
47+
// print(self.pager.size(forNumberOfPages: 20))
48+
// print(self.pager.size(forNumberOfPages: 30))
49+
}
50+
3251
var didLayout = false
3352
override func viewDidLayoutSubviews() {
3453
if !self.didLayout {
2.16 KB
Loading

bk2ch12p580stepper/ch25p853stepper/ViewController.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ class ViewController: UIViewController {
4747
self.prog.setProgress(Float(step.value / (step.maximumValue - step.minimumValue)), animated:true)
4848
}
4949

50+
var customize : Bool { false }
5051
override func viewDidLoad() {
5152
super.viewDidLoad()
52-
53-
// return;
53+
// disastrous
54+
// self.stepper.bounds.size.height = self.stepper.bounds.height - 10
55+
guard self.customize else { return }
5456

5557
self.stepper.tintColor = UIColor.yellow
5658

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14092" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17147" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
7-
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14081.1"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17120"/>
96
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
107
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
118
</dependencies>
@@ -18,30 +15,35 @@
1815
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1916
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2017
<subviews>
21-
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="gIK-bs-UBw">
22-
<rect key="frame" x="0.0" y="64" width="375" height="216"/>
23-
<date key="date" timeIntervalSinceReferenceDate="450983804.334001">
24-
<!--2015-04-17 17:16:44 +0000-->
25-
</date>
18+
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" style="wheels" translatesAutoresizingMaskIntoConstraints="NO" id="gIK-bs-UBw">
19+
<rect key="frame" x="0.0" y="44" width="375" height="216"/>
2620
<connections>
2721
<action selector="dateChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="sQF-Zh-hAo"/>
2822
</connections>
2923
</datePicker>
24+
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="time" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="ETH-KN-X2k">
25+
<rect key="frame" x="16" y="280" width="343" height="216"/>
26+
</datePicker>
3027
</subviews>
28+
<viewLayoutGuide key="safeArea" id="m7Q-VR-0fX"/>
3129
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3230
<constraints>
31+
<constraint firstItem="ETH-KN-X2k" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="AlR-ex-jEB"/>
32+
<constraint firstAttribute="trailingMargin" secondItem="ETH-KN-X2k" secondAttribute="trailing" id="Pxx-xV-y3k"/>
33+
<constraint firstItem="ETH-KN-X2k" firstAttribute="top" secondItem="gIK-bs-UBw" secondAttribute="bottom" constant="20" id="XVN-ew-nqj"/>
3334
<constraint firstItem="gIK-bs-UBw" firstAttribute="leading" secondItem="m7Q-VR-0fX" secondAttribute="leading" id="Y0D-Eg-Svy"/>
3435
<constraint firstItem="gIK-bs-UBw" firstAttribute="top" secondItem="m7Q-VR-0fX" secondAttribute="top" constant="44" id="hor-B5-Pdi"/>
3536
<constraint firstItem="m7Q-VR-0fX" firstAttribute="trailing" secondItem="gIK-bs-UBw" secondAttribute="trailing" id="usk-zA-YaW"/>
3637
</constraints>
37-
<viewLayoutGuide key="safeArea" id="m7Q-VR-0fX"/>
3838
</view>
3939
<connections>
4040
<outlet property="dp" destination="gIK-bs-UBw" id="TXP-9h-9z9"/>
41+
<outlet property="dp2" destination="ETH-KN-X2k" id="FHp-ae-eOi"/>
4142
</connections>
4243
</viewController>
4344
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
4445
</objects>
46+
<point key="canvasLocation" x="-23" y="125"/>
4547
</scene>
4648
</scenes>
4749
</document>

bk2ch12p582datePicker/bk2ch12p582datePicker/ViewController.swift

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11

22
import UIKit
33

4+
extension UIControl {
5+
func addAction(for event: UIControl.Event,
6+
handler: @escaping UIActionHandler) {
7+
self.addAction(UIAction(handler:handler), for:event)
8+
}
9+
}
10+
11+
412
class ViewController: UIViewController {
513
@IBOutlet weak var dp: UIDatePicker!
6-
14+
@IBOutlet weak var dp2: UIDatePicker!
15+
716

817

918
override func viewDidLoad() {
1019
super.viewDidLoad()
1120
// Do any additional setup after loading the view, typically from a nib.
1221

22+
dp2.datePickerMode = .time
23+
dp2.preferredDatePickerStyle = .inline
24+
dp2.minuteInterval = 30
25+
dp2.addAction(for: .valueChanged) { action in
26+
print((action.sender as! UIDatePicker).date)
27+
}
1328

14-
var which : Int { return 1 }
29+
var which : Int { return 2 }
1530

1631
switch which {
1732
case 1:
33+
// dp.preferredDatePickerStyle = .inline
1834
dp.datePickerMode = .date
1935
// dp.datePickerMode = .dateAndTime
20-
var dc = DateComponents(year:1954, month:1, day:1)
36+
var dc = DateComponents(year:1954, month:1, day:2)
2137
let c = Calendar(identifier:.gregorian)
2238
let d1 = c.date(from: dc)!
2339
dp.minimumDate = d1

bk2ch12p585slider/ch25p860slider/MySlider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class MySlider: UISlider {
6363
let delta = Float(percentage) * (s.maximumValue - s.minimumValue)
6464
let value = s.minimumValue + delta
6565
delay(0.1) {
66-
UIView.animate(withDuration: 0.15) {
66+
UIView.animate(withDuration: 1) {
6767
s.setValue(value, animated:true) // NB behold the secret of getting animation
6868
}
6969
}

0 commit comments

Comments
 (0)