| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,8 +12,7 @@ | |||
| 12 | 12 | 9F7476F61F288C33000E2B6A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9F7476F41F288C33000E2B6A /* Main.storyboard */; }; | |
| 13 | 13 | 9F7476F81F288C33000E2B6A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9F7476F71F288C33000E2B6A /* Assets.xcassets */; }; | |
| 14 | 14 | 9F7476FB1F288C33000E2B6A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9F7476F91F288C33000E2B6A /* LaunchScreen.storyboard */; }; | |
| 15 | - 9F7477031F288C66000E2B6A /* AlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F7477021F288C66000E2B6A /* AlertViewController.swift */; }; | ||
| 16 | - 9F7477051F28BD76000E2B6A /* UIAlertAction+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F7477041F28BD76000E2B6A /* UIAlertAction+Extensions.swift */; }; | ||
| 15 | + 9F7477031F288C66000E2B6A /* ImageAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F7477021F288C66000E2B6A /* ImageAlertViewController.swift */; }; | ||
| 17 | 16 | /* End PBXBuildFile section */ | |
| 18 | 17 | ||
| 19 | 18 | /* Begin PBXFileReference section */ | |
@@ -25,8 +24,7 @@ | |||
| 25 | 24 | 9F7476F71F288C33000E2B6A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; | |
| 26 | 25 | 9F7476FA1F288C33000E2B6A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; | |
| 27 | 26 | 9F7476FC1F288C33000E2B6A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; | |
| 28 | - 9F7477021F288C66000E2B6A /* AlertViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertViewController.swift; sourceTree = "<group>"; }; | ||
| 29 | - 9F7477041F28BD76000E2B6A /* UIAlertAction+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertAction+Extensions.swift"; sourceTree = "<group>"; }; | ||
| 27 | + 9F7477021F288C66000E2B6A /* ImageAlertViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageAlertViewController.swift; sourceTree = "<group>"; }; | ||
| 30 | 28 | /* End PBXFileReference section */ | |
| 31 | 29 | ||
| 32 | 30 | /* Begin PBXFrameworksBuildPhase section */ | |
@@ -62,8 +60,7 @@ | |||
| 62 | 60 | children = ( | |
| 63 | 61 | 9F7476F01F288C33000E2B6A /* AppDelegate.swift */, | |
| 64 | 62 | 9F7476F21F288C33000E2B6A /* ViewController.swift */, | |
| 65 | - 9F7477021F288C66000E2B6A /* AlertViewController.swift */, | ||
| 66 | - 9F7477041F28BD76000E2B6A /* UIAlertAction+Extensions.swift */, | ||
| 63 | + 9F7477021F288C66000E2B6A /* ImageAlertViewController.swift */, | ||
| 67 | 64 | 9F7476F41F288C33000E2B6A /* Main.storyboard */, | |
| 68 | 65 | 9F7476F71F288C33000E2B6A /* Assets.xcassets */, | |
| 69 | 66 | 9F7476F91F288C33000E2B6A /* LaunchScreen.storyboard */, | |
@@ -104,7 +101,7 @@ | |||
| 104 | 101 | TargetAttributes = { | |
| 105 | 102 | 9F7476EC1F288C33000E2B6A = { | |
| 106 | 103 | CreatedOnToolsVersion = 8.3.3; | |
| 107 | - DevelopmentTeam = T8TH53QYXW; | ||
| 104 | + DevelopmentTeam = J4Z2NCTR3S; | ||
| 108 | 105 | ProvisioningStyle = Automatic; | |
| 109 | 106 | }; | |
| 110 | 107 | }; | |
@@ -145,9 +142,8 @@ | |||
| 145 | 142 | isa = PBXSourcesBuildPhase; | |
| 146 | 143 | buildActionMask = 2147483647; | |
| 147 | 144 | files = ( | |
| 148 | - 9F7477051F28BD76000E2B6A /* UIAlertAction+Extensions.swift in Sources */, | ||
| 149 | 145 | 9F7476F31F288C33000E2B6A /* ViewController.swift in Sources */, | |
| 150 | - 9F7477031F288C66000E2B6A /* AlertViewController.swift in Sources */, | ||
| 146 | + 9F7477031F288C66000E2B6A /* ImageAlertViewController.swift in Sources */, | ||
| 151 | 147 | 9F7476F11F288C33000E2B6A /* AppDelegate.swift in Sources */, | |
| 152 | 148 | ); | |
| 153 | 149 | runOnlyForDeploymentPostprocessing = 0; | |
@@ -273,7 +269,7 @@ | |||
| 273 | 269 | isa = XCBuildConfiguration; | |
| 274 | 270 | buildSettings = { | |
| 275 | 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |
| 276 | - DEVELOPMENT_TEAM = T8TH53QYXW; | ||
| 272 | + DEVELOPMENT_TEAM = J4Z2NCTR3S; | ||
| 277 | 273 | INFOPLIST_FILE = AlertViewController/Info.plist; | |
| 278 | 274 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; | |
| 279 | 275 | PRODUCT_BUNDLE_IDENTIFIER = uk.co.stringcode.AlertViewController; | |
@@ -286,7 +282,7 @@ | |||
| 286 | 282 | isa = XCBuildConfiguration; | |
| 287 | 283 | buildSettings = { | |
| 288 | 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |
| 289 | - DEVELOPMENT_TEAM = T8TH53QYXW; | ||
| 285 | + DEVELOPMENT_TEAM = J4Z2NCTR3S; | ||
| 290 | 286 | INFOPLIST_FILE = AlertViewController/Info.plist; | |
| 291 | 287 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; | |
| 292 | 288 | PRODUCT_BUNDLE_IDENTIFIER = uk.co.stringcode.AlertViewController; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,6 +84,11 @@ | |||
| 84 | 84 | "idiom" : "ipad", | |
| 85 | 85 | "size" : "83.5x83.5", | |
| 86 | 86 | "scale" : "2x" | |
| 87 | + }, | ||
| 88 | + { | ||
| 89 | + "idiom" : "ios-marketing", | ||
| 90 | + "size" : "1024x1024", | ||
| 91 | + "scale" : "1x" | ||
| 87 | 92 | } | |
| 88 | 93 | ], | |
| 89 | 94 | "info" : { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | - <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
| 2 | + <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
| 3 | 3 | <device id="retina4_7" orientation="portrait"> | |
| 4 | 4 | <adaptation id="fullscreen"/> | |
| 5 | 5 | </device> | |
| 6 | 6 | <dependencies> | |
| 7 | 7 | <deployment identifier="iOS"/> | |
| 8 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> | ||
| 8 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> | ||
| 9 | 9 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | |
| 10 | 10 | </dependencies> | |
| 11 | 11 | <scenes> | |
@@ -28,11 +28,20 @@ | |||
| 28 | 28 | <action selector="doStuffAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="yGK-g7-5Nk"/> | |
| 29 | 29 | </connections> | |
| 30 | 30 | </button> | |
| 31 | + <button opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gjT-Pu-Ljd"> | ||
| 32 | + <rect key="frame" x="124" y="386" width="126" height="30"/> | ||
| 33 | + <state key="normal" title="Show ActionSheet"/> | ||
| 34 | + <connections> | ||
| 35 | + <action selector="doStuffAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ZMW-bj-JQb"/> | ||
| 36 | + </connections> | ||
| 37 | + </button> | ||
| 31 | 38 | </subviews> | |
| 32 | 39 | <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
| 33 | 40 | <constraints> | |
| 41 | + <constraint firstItem="gjT-Pu-Ljd" firstAttribute="top" secondItem="hew-63-qSi" secondAttribute="bottom" constant="37.5" id="pFO-l4-GNX"/> | ||
| 34 | 42 | <constraint firstItem="hew-63-qSi" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="pgn-xm-bYo"/> | |
| 35 | 43 | <constraint firstItem="hew-63-qSi" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="rbr-61-WNu"/> | |
| 44 | + <constraint firstItem="gjT-Pu-Ljd" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="wXG-R7-bAW"/> | ||
| 36 | 45 | </constraints> | |
| 37 | 46 | </view> | |
| 38 | 47 | </viewController> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,17 +8,48 @@ | |||
| 8 | 8 | ||
| 9 | 9 | import UIKit | |
| 10 | 10 | ||
| 11 | + | ||
| 12 | + // MARK: - UIAlertController | ||
| 13 | + | ||
| 11 | 14 | /// Adds ability to display `UIImage` above the title label of `UIAlertController`. | |
| 12 | 15 | /// Functionality is achieved by adding “\n” characters to `title`, to make space | |
| 13 | 16 | /// for `UIImageView` to be added to `UIAlertController.view`. Set `title` as | |
| 14 | 17 | /// normal but when retrieving value use `originalTitle` property. | |
| 15 | - class AlertController: UIAlertController { | ||
| 18 | + class ImageAlertController: UIAlertController { | ||
| 16 | 19 | /// - Return: value that was set on `title` | |
| 17 | 20 | private(set) var originalTitle: String? | |
| 18 | 21 | private var spaceAdjustedTitle: String = "" | |
| 19 | 22 | private weak var imageView: UIImageView? = nil | |
| 20 | 23 | private var previousImgViewSize: CGSize = .zero | |
| 21 | - | ||
| 24 | + private var imageViewSize: CGSize? | ||
| 25 | + | ||
| 26 | + /// - parameter image: `UIImage` to be displayed about title label | ||
| 27 | + var titleImage: UIImage? { | ||
| 28 | + set { | ||
| 29 | + guard let imageView = self.imageView else { | ||
| 30 | + let imageView = UIImageView(image: newValue) | ||
| 31 | + if let size = imageViewSize { | ||
| 32 | + imageView.frame.size = size | ||
| 33 | + } | ||
| 34 | + self.view.addSubview(imageView) | ||
| 35 | + self.imageView = imageView | ||
| 36 | + return | ||
| 37 | + } | ||
| 38 | + imageView.image = newValue | ||
| 39 | + } | ||
| 40 | + get { | ||
| 41 | + return imageView?.image | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + convenience init(image: UIImage?, size: CGSize? = nil, title: String?, message: String?, preferredStyle: UIAlertControllerStyle) { | ||
| 46 | + self.init(title: title, message: message, preferredStyle: preferredStyle) | ||
| 47 | + | ||
| 48 | + guard let image = image else { return } | ||
| 49 | + imageViewSize = size | ||
| 50 | + titleImage = image | ||
| 51 | + } | ||
| 52 | + | ||
| 22 | 53 | override var title: String? { | |
| 23 | 54 | didSet { | |
| 24 | 55 | // Keep track of original title | |
@@ -28,17 +59,6 @@ class AlertController: UIAlertController { | |||
| 28 | 59 | } | |
| 29 | 60 | } | |
| 30 | 61 | ||
| 31 | - /// - parameter image: `UIImage` to be displayed about title label | ||
| 32 | - func setTitleImage(_ image: UIImage?) { | ||
| 33 | - guard let imageView = self.imageView else { | ||
| 34 | - let imageView = UIImageView(image: image) | ||
| 35 | - self.view.addSubview(imageView) | ||
| 36 | - self.imageView = imageView | ||
| 37 | - return | ||
| 38 | - } | ||
| 39 | - imageView.image = image | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | 62 | // MARK: - Layout code | |
| 43 | 63 | ||
| 44 | 64 | override func viewDidLayoutSubviews() { | |
@@ -80,9 +100,43 @@ class AlertController: UIAlertController { | |||
| 80 | 100 | ||
| 81 | 101 | struct Constants { | |
| 82 | 102 | static var paddingAlert: CGFloat = 22 | |
| 83 | - static var paddingSheet: CGFloat = 11 | ||
| 103 | + static var paddingSheet: CGFloat = 16 | ||
| 84 | 104 | static func padding(for style: UIAlertControllerStyle) -> CGFloat { | |
| 85 | 105 | return style == .alert ? Constants.paddingAlert : Constants.paddingSheet | |
| 86 | 106 | } | |
| 87 | 107 | } | |
| 88 | 108 | } | |
| 109 | + | ||
| 110 | + | ||
| 111 | + // MARK: - UIAlertAction | ||
| 112 | + | ||
| 113 | + /// Adds ability to display image left of the action title, by leveraging KVC. | ||
| 114 | + /// Also checks whether `UIAlertAction` responds to appropriate selector to | ||
| 115 | + /// avoid crashes if property is not available in the future. | ||
| 116 | + extension UIAlertAction { | ||
| 117 | + | ||
| 118 | + convenience init(title: String?, image: UIImage?, style: UIAlertActionStyle, handler: ((UIAlertAction) -> Swift.Void)? = nil) { | ||
| 119 | + self.init(title: title, style: style, handler: handler) | ||
| 120 | + | ||
| 121 | + actionImage = image | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /// Image to display left of the action title | ||
| 125 | + var actionImage: UIImage? { | ||
| 126 | + get { | ||
| 127 | + if self.responds(to: Selector(Constants.imageKey)) { | ||
| 128 | + return self.value(forKey: Constants.imageKey) as? UIImage | ||
| 129 | + } | ||
| 130 | + return nil | ||
| 131 | + } | ||
| 132 | + set { | ||
| 133 | + if self.responds(to: Selector(Constants.imageKey)) { | ||
| 134 | + self.setValue(newValue, forKey: Constants.imageKey) | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + private struct Constants { | ||
| 140 | + static var imageKey = "image" | ||
| 141 | + } | ||
| 142 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,13 +10,18 @@ import UIKit | |||
| 10 | 10 | ||
| 11 | 11 | class ViewController: UIViewController { | |
| 12 | 12 | ||
| 13 | - @IBAction func doStuffAction(_ sender: Any) { | ||
| 14 | - // Create AlertController | ||
| 15 | - let alert = AlertController(title: "Tesing", message: "Wubba lubba dub dub", preferredStyle: .alert) | ||
| 16 | - alert.setTitleImage(UIImage(named: "alert")) | ||
| 13 | + @IBAction func doStuffAction(_ sender: UIButton) { | ||
| 14 | + let style: UIAlertControllerStyle = sender.tag == 0 ? .alert : .actionSheet | ||
| 15 | + let alert = ImageAlertController(image: UIImage(named: "alert"), size: CGSize(width: 44, height: 44), title: "Tesing", message: "Wubba lubba dub dub", preferredStyle: style) | ||
| 16 | + | ||
| 17 | + if sender.tag > 0 { | ||
| 18 | + alert.popoverPresentationController?.sourceView = sender | ||
| 19 | + alert.popoverPresentationController?.sourceRect = sender.bounds | ||
| 20 | + alert.modalPresentationStyle = .popover | ||
| 21 | + } | ||
| 22 | + | ||
| 17 | 23 | // Add actions | |
| 18 | - let action = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) | ||
| 19 | - action.actionImage = UIImage(named: "close") | ||
| 24 | + let action = UIAlertAction(title: "Cancel", image: UIImage(named: "close"), style: .cancel, handler: nil) | ||
| 20 | 25 | alert.addAction(UIAlertAction(title: "Default", style: .default, handler: nil)) | |
| 21 | 26 | alert.addAction(UIAlertAction(title: "Destroy", style: .destructive, handler: nil)) | |
| 22 | 27 | alert.addAction(action) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments