Skip to content

Commit ef52a3c

Browse files
author
szl
committed
STAlertView
1 parent e4bc55f commit ef52a3c

File tree

15 files changed

+467
-6
lines changed

15 files changed

+467
-6
lines changed

STKitSwift.xcodeproj/project.pbxproj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0492AF2522C9B7EA00F73D31 /* STHUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0492AF2422C9B7EA00F73D31 /* STHUD.swift */; };
11+
0492AF2C22C9B9A500F73D31 /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0492AF2B22C9B9A500F73D31 /* SnapKit.framework */; };
12+
0492AF2E22C9B9CF00F73D31 /* STAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0492AF2D22C9B9CF00F73D31 /* STAlertView.swift */; };
13+
0492AF3022C9C12D00F73D31 /* UIViewController+STKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0492AF2F22C9C12D00F73D31 /* UIViewController+STKit.swift */; };
1014
6796E4AD21D21F3900C2C5E4 /* STKitSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6796E4A321D21F3800C2C5E4 /* STKitSwift.framework */; };
1115
6796E4B221D21F3900C2C5E4 /* STKitSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6796E4B121D21F3900C2C5E4 /* STKitSwiftTests.swift */; };
1216
6796E4B421D21F3900C2C5E4 /* STKitSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 6796E4A621D21F3800C2C5E4 /* STKitSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -26,6 +30,10 @@
2630
/* End PBXContainerItemProxy section */
2731

2832
/* Begin PBXFileReference section */
33+
0492AF2422C9B7EA00F73D31 /* STHUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STHUD.swift; sourceTree = "<group>"; };
34+
0492AF2B22C9B9A500F73D31 /* SnapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SnapKit.framework; sourceTree = "<group>"; };
35+
0492AF2D22C9B9CF00F73D31 /* STAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STAlertView.swift; sourceTree = "<group>"; };
36+
0492AF2F22C9C12D00F73D31 /* UIViewController+STKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+STKit.swift"; sourceTree = "<group>"; };
2937
6796E4A321D21F3800C2C5E4 /* STKitSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = STKitSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3038
6796E4A621D21F3800C2C5E4 /* STKitSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = STKitSwift.h; sourceTree = "<group>"; };
3139
6796E4A721D21F3900C2C5E4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -41,6 +49,7 @@
4149
isa = PBXFrameworksBuildPhase;
4250
buildActionMask = 2147483647;
4351
files = (
52+
0492AF2C22C9B9A500F73D31 /* SnapKit.framework in Frameworks */,
4453
);
4554
runOnlyForDeploymentPostprocessing = 0;
4655
};
@@ -55,12 +64,21 @@
5564
/* End PBXFrameworksBuildPhase section */
5665

5766
/* Begin PBXGroup section */
67+
0492AF2622C9B84200F73D31 /* Frameworks */ = {
68+
isa = PBXGroup;
69+
children = (
70+
0492AF2B22C9B9A500F73D31 /* SnapKit.framework */,
71+
);
72+
name = Frameworks;
73+
sourceTree = "<group>";
74+
};
5875
6796E49921D21F3800C2C5E4 = {
5976
isa = PBXGroup;
6077
children = (
6178
6796E4A521D21F3800C2C5E4 /* STKitSwift */,
6279
6796E4B021D21F3900C2C5E4 /* STKitSwiftTests */,
6380
6796E4A421D21F3800C2C5E4 /* Products */,
81+
0492AF2622C9B84200F73D31 /* Frameworks */,
6482
);
6583
sourceTree = "<group>";
6684
};
@@ -76,9 +94,12 @@
7694
6796E4A521D21F3800C2C5E4 /* STKitSwift */ = {
7795
isa = PBXGroup;
7896
children = (
97+
0492AF2422C9B7EA00F73D31 /* STHUD.swift */,
7998
6796E4A621D21F3800C2C5E4 /* STKitSwift.h */,
8099
6796E4EE21D220A500C2C5E4 /* UIView+STKit.swift */,
81100
67FB10BE21E054A20012DE4A /* Date+STKit.swift */,
101+
0492AF2D22C9B9CF00F73D31 /* STAlertView.swift */,
102+
0492AF2F22C9C12D00F73D31 /* UIViewController+STKit.swift */,
82103
6796E4A721D21F3900C2C5E4 /* Info.plist */,
83104
);
84105
path = STKitSwift;
@@ -203,6 +224,9 @@
203224
buildActionMask = 2147483647;
204225
files = (
205226
6796E4EF21D220A500C2C5E4 /* UIView+STKit.swift in Sources */,
227+
0492AF2522C9B7EA00F73D31 /* STHUD.swift in Sources */,
228+
0492AF2E22C9B9CF00F73D31 /* STAlertView.swift in Sources */,
229+
0492AF3022C9C12D00F73D31 /* UIViewController+STKit.swift in Sources */,
206230
67FB10BF21E054A20012DE4A /* Date+STKit.swift in Sources */,
207231
);
208232
runOnlyForDeploymentPostprocessing = 0;
@@ -360,8 +384,13 @@
360384
DYLIB_COMPATIBILITY_VERSION = 1;
361385
DYLIB_CURRENT_VERSION = 1;
362386
DYLIB_INSTALL_NAME_BASE = "@rpath";
387+
FRAMEWORK_SEARCH_PATHS = (
388+
"$(inherited)",
389+
"$(PROJECT_DIR)",
390+
);
363391
INFOPLIST_FILE = STKitSwift/Info.plist;
364392
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
393+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
365394
LD_RUNPATH_SEARCH_PATHS = (
366395
"$(inherited)",
367396
"@executable_path/Frameworks",
@@ -387,8 +416,13 @@
387416
DYLIB_COMPATIBILITY_VERSION = 1;
388417
DYLIB_CURRENT_VERSION = 1;
389418
DYLIB_INSTALL_NAME_BASE = "@rpath";
419+
FRAMEWORK_SEARCH_PATHS = (
420+
"$(inherited)",
421+
"$(PROJECT_DIR)",
422+
);
390423
INFOPLIST_FILE = STKitSwift/Info.plist;
391424
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
425+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
392426
LD_RUNPATH_SEARCH_PATHS = (
393427
"$(inherited)",
394428
"@executable_path/Frameworks",

STKitSwift/STAlertView.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// STAlertView.swift
3+
// STKitSwift
4+
//
5+
// Created by mac on 2019/7/1.
6+
//
7+
8+
import UIKit
9+
10+
public class STAlertView: UIAlertController {
11+
12+
@discardableResult
13+
public class func show(title:String?, message: String?, cancelTitle: String?, otherTitle: String?, completion:((Int) -> Void)? = nil) -> STAlertView{
14+
let alertView = STAlertView.init(title: title, message: message, preferredStyle: .alert)
15+
16+
if let title = cancelTitle {
17+
let alertCancel: UIAlertAction = UIAlertAction.init(title: title, style: .cancel) { (_) in
18+
completion?(0)
19+
}
20+
alertView.addAction(alertCancel)
21+
}
22+
23+
if let title = otherTitle {
24+
let alertOther: UIAlertAction = UIAlertAction.init(title: title, style: .default) { (_) in
25+
completion?(1)
26+
}
27+
alertView.addAction(alertOther)
28+
}
29+
30+
let controller = UIViewController.topMost ?? UIViewController()
31+
controller.present(alertView, animated: true, completion: nil)
32+
return alertView
33+
}
34+
35+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// UIViewController+STKit.swift
3+
// STKitSwift
4+
//
5+
// Created by mac on 2019/7/1.
6+
//
7+
8+
import UIKit
9+
10+
public extension UIViewController {
11+
private class var sharedApplication: UIApplication? {
12+
let selector = NSSelectorFromString("sharedApplication")
13+
return UIApplication.perform(selector)?.takeUnretainedValue() as? UIApplication
14+
}
15+
16+
/// Returns the current application's top most view controller.
17+
class var topMost: UIViewController? {
18+
guard let currentWindows = self.sharedApplication?.windows else { return nil }
19+
var rootViewController: UIViewController?
20+
for window in currentWindows {
21+
if let windowRootViewController = window.rootViewController {
22+
rootViewController = windowRootViewController
23+
break
24+
}
25+
}
26+
27+
return self.topMost(of: rootViewController)
28+
}
29+
30+
/// Returns the top most view controller from given view controller's stack.
31+
class func topMost(of viewController: UIViewController?) -> UIViewController? {
32+
// presented view controller
33+
if let presentedViewController = viewController?.presentedViewController {
34+
return self.topMost(of: presentedViewController)
35+
}
36+
37+
// UITabBarController
38+
if let tabBarController = viewController as? UITabBarController,
39+
let selectedViewController = tabBarController.selectedViewController {
40+
return self.topMost(of: selectedViewController)
41+
}
42+
43+
// UINavigationController
44+
if let navigationController = viewController as? UINavigationController,
45+
let visibleViewController = navigationController.visibleViewController {
46+
return self.topMost(of: visibleViewController)
47+
}
48+
49+
// UIPageController
50+
if let pageViewController = viewController as? UIPageViewController,
51+
pageViewController.viewControllers?.count == 1 {
52+
return self.topMost(of: pageViewController.viewControllers?.first)
53+
}
54+
55+
// child view controller
56+
for subview in viewController?.view?.subviews ?? [] {
57+
if let childViewController = subview.next as? UIViewController {
58+
return self.topMost(of: childViewController)
59+
}
60+
}
61+
return viewController
62+
}
63+
}

STKitSwiftDemo/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ SPEC CHECKSUMS:
1919
SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf
2020
STKitSwift: 5116700c2df00d3c5e11c721270ae294f8e6ff37
2121

22-
PODFILE CHECKSUM: 9dabf58c314a3931f2312bad964a07eb3e9c33b0
22+
PODFILE CHECKSUM: b5ed0d54d1e94a22b025305f0a758b0305d262ac
2323

2424
COCOAPODS: 1.6.1

STKitSwiftDemo/STKitSwiftDemo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
0492AF2322C9A6C000F73D31 /* STHUDController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0492AF2222C9A6C000F73D31 /* STHUDController.swift */; };
11+
0492AF3222C9C29700F73D31 /* STAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0492AF3122C9C29700F73D31 /* STAlertController.swift */; };
1112
4D69364BE872B2A6668E6F1A /* Pods_STKitSwiftDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B46BAF2544514D16BC81115 /* Pods_STKitSwiftDemo.framework */; };
1213
6784885E21B7CCFE0002FDF5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6784885D21B7CCFE0002FDF5 /* AppDelegate.swift */; };
1314
6784886321B7CCFE0002FDF5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6784886121B7CCFE0002FDF5 /* Main.storyboard */; };
@@ -17,6 +18,7 @@
1718

1819
/* Begin PBXFileReference section */
1920
0492AF2222C9A6C000F73D31 /* STHUDController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STHUDController.swift; sourceTree = "<group>"; };
21+
0492AF3122C9C29700F73D31 /* STAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STAlertController.swift; sourceTree = "<group>"; };
2022
3B46BAF2544514D16BC81115 /* Pods_STKitSwiftDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_STKitSwiftDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2123
6784885A21B7CCFE0002FDF5 /* STKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = STKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2224
6784885D21B7CCFE0002FDF5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -72,6 +74,7 @@
7274
children = (
7375
6784885D21B7CCFE0002FDF5 /* AppDelegate.swift */,
7476
0492AF2222C9A6C000F73D31 /* STHUDController.swift */,
77+
0492AF3122C9C29700F73D31 /* STAlertController.swift */,
7578
6784886121B7CCFE0002FDF5 /* Main.storyboard */,
7679
6784886421B7CD000002FDF5 /* Assets.xcassets */,
7780
6784886621B7CD000002FDF5 /* LaunchScreen.storyboard */,
@@ -202,6 +205,7 @@
202205
isa = PBXSourcesBuildPhase;
203206
buildActionMask = 2147483647;
204207
files = (
208+
0492AF3222C9C29700F73D31 /* STAlertController.swift in Sources */,
205209
0492AF2322C9A6C000F73D31 /* STHUDController.swift in Sources */,
206210
6784885E21B7CCFE0002FDF5 /* AppDelegate.swift in Sources */,
207211
);

STKitSwiftDemo/STKitSwiftDemo/Base.lproj/Main.storyboard

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,41 @@
6060
</objects>
6161
<point key="canvasLocation" x="40.579710144927539" y="219.64285714285714"/>
6262
</scene>
63+
<!--Alert Controller-->
64+
<scene sceneID="EYz-MP-K7n">
65+
<objects>
66+
<viewController id="yK6-Xs-q8C" customClass="STAlertController" customModule="STKitSwiftDemo" customModuleProvider="target" sceneMemberID="viewController">
67+
<view key="view" contentMode="scaleToFill" id="ss8-wH-ID1">
68+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
69+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
70+
<subviews>
71+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IwQ-Iv-59K">
72+
<rect key="frame" x="107" y="423" width="200" height="50"/>
73+
<color key="backgroundColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
74+
<constraints>
75+
<constraint firstAttribute="height" constant="50" id="tI4-DP-hgK"/>
76+
<constraint firstAttribute="width" constant="200" id="y9A-Rk-k1U"/>
77+
</constraints>
78+
<state key="normal" title="Show AlertView">
79+
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
80+
</state>
81+
<connections>
82+
<action selector="actionButton:" destination="yK6-Xs-q8C" eventType="touchUpInside" id="7J7-Y4-Nu5"/>
83+
</connections>
84+
</button>
85+
</subviews>
86+
<color key="backgroundColor" red="0.8770066353" green="0.97549229449999997" blue="0.98584653249999998" alpha="1" colorSpace="calibratedRGB"/>
87+
<constraints>
88+
<constraint firstItem="IwQ-Iv-59K" firstAttribute="centerX" secondItem="ss8-wH-ID1" secondAttribute="centerX" id="JvS-Zc-uTb"/>
89+
<constraint firstItem="IwQ-Iv-59K" firstAttribute="centerY" secondItem="ss8-wH-ID1" secondAttribute="centerY" id="dJM-cN-Gyr"/>
90+
</constraints>
91+
<viewLayoutGuide key="safeArea" id="vVh-sh-TsD"/>
92+
</view>
93+
</viewController>
94+
<placeholder placeholderIdentifier="IBFirstResponder" id="VEQ-vz-J0p" userLabel="First Responder" sceneMemberID="firstResponder"/>
95+
</objects>
96+
<point key="canvasLocation" x="41" y="875"/>
97+
</scene>
6398
<!--Table View Controller-->
6499
<scene sceneID="sUp-LJ-0BD">
65100
<objects>
@@ -98,13 +133,32 @@
98133
<segue destination="3Zu-ep-hZS" kind="show" id="4Q4-O6-ZBf"/>
99134
</connections>
100135
</tableViewCell>
101-
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="yPK-Ar-xGL">
136+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="m6v-0y-HPf" detailTextLabel="zC0-VG-Iym" style="IBUITableViewCellStyleValue1" id="yPK-Ar-xGL">
102137
<rect key="frame" x="0.0" y="79" width="414" height="44"/>
103138
<autoresizingMask key="autoresizingMask"/>
104139
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="yPK-Ar-xGL" id="uYH-wV-259">
105140
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
106141
<autoresizingMask key="autoresizingMask"/>
142+
<subviews>
143+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="STView" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="m6v-0y-HPf">
144+
<rect key="frame" x="20" y="12" width="58" height="20.5"/>
145+
<autoresizingMask key="autoresizingMask"/>
146+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
147+
<nil key="textColor"/>
148+
<nil key="highlightedColor"/>
149+
</label>
150+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="STAlertView" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="zC0-VG-Iym">
151+
<rect key="frame" x="301" y="12" width="93" height="20.5"/>
152+
<autoresizingMask key="autoresizingMask"/>
153+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
154+
<nil key="textColor"/>
155+
<nil key="highlightedColor"/>
156+
</label>
157+
</subviews>
107158
</tableViewCellContentView>
159+
<connections>
160+
<segue destination="yK6-Xs-q8C" kind="show" id="cfN-aW-TPb"/>
161+
</connections>
108162
</tableViewCell>
109163
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="A4t-bA-KGf">
110164
<rect key="frame" x="0.0" y="123" width="414" height="44"/>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// STAlertController.swift
3+
// STKitSwiftDemo
4+
//
5+
// Created by mac on 2019/7/1.
6+
// Copyright © 2019 沈兆良. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
import STKitSwift
12+
class STAlertController: UIViewController {
13+
14+
// MARK: 1.lift cycle
15+
deinit {
16+
print("------------ STAlertController deinit ------------")
17+
}
18+
// MARK: 2.private methods
19+
20+
// MARK: 3.event response
21+
22+
@IBAction func actionButton(_ sender: UIButton) {
23+
let title = "Flutter 与 iOS 原生 WebView 对比"
24+
let message = "在iOS中使用的就是原生的WKWebView,所以总体和 native WKWebView 表现差不多。如果是混编项目中,因为它被包了一层,所以页面加载上存在一定的劣势,所以混编项目中仍然推荐使用 WKWebView。不过如果从多端考虑、以及项目可迁移等,那么使用也未尝不可,就是维护成本要增加一些,需要维护两套 webView。这个就需要根据自己的情况自己取舍了"
25+
STAlertView.show(title: title, message: message, cancelTitle: "取消", otherTitle: "确定") { (item) in
26+
print(item)
27+
28+
}
29+
}
30+
31+
// MARK: 4.interface
32+
33+
// MARK: 5.getter
34+
35+
}

STKitSwiftDemo/STKitSwiftDemo/STHUDController.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ class STHUDController: UIViewController {
1818

1919
@IBAction func actionButton(_ sender: UIButton) {
2020
STHUD.show(textView.text)
21-
// STHUD.show(textView.text) { (finish) in
22-
// print(finish)
23-
// }
2421
}
2522

2623
// MARK: 4.interface
27-
2824
@IBOutlet weak var textView: UITextView!
2925
// MARK: 5.getter
3026

0 commit comments

Comments
 (0)