├── README.md ├── UIKit component handling.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── thyeon.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── thyeon.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── UIKit component handling.xcscheme │ └── xcschememanagement.plist ├── UIKit component handling ├── AppDelegate.swift ├── ComponentList.swift ├── ComponentViewController │ ├── ActionSheetVC.swift │ ├── ActivityIndicatorVC.swift │ ├── AddDeleteTableViewVC.swift │ ├── AlertVC.swift │ ├── AnimateButtonVC.swift │ ├── AnimationSummaryVC.swift │ ├── AttachmentVC.swift │ ├── BarButtonItemVC.swift │ ├── BlurEffectVC.swift │ ├── ButtonVC.swift │ ├── ButtonsVC.swift │ ├── CharacterLimitAlertVC.swift │ ├── CollectionViewCellVC.swift │ ├── CollectionViewVC.swift │ ├── ComposingImageVC.swift │ ├── CustomizeButtonVC.swift │ ├── DatePickerVC.swift │ ├── DeletePartsVC.swift │ ├── DisplayViewVC.swift │ ├── DragViewVC.swift │ ├── EffectProcessVC.swift │ ├── ExtendingButtonTableViewVC.swift │ ├── FontVC.swift │ ├── GestureVC.swift │ ├── GravityViewVC.swift │ ├── ImagePickerVC.swift │ ├── ImageViewVC.swift │ ├── LabelVC.swift │ ├── LimitedTextFieldVC.swift │ ├── MenuItemVC.swift │ ├── MotionEffectVC.swift │ ├── MultipleButtonsVC.swift │ ├── PageControlVC.swift │ ├── PasswordAlertVC.swift │ ├── PasswordTextFieldVC.swift │ ├── PickerViewVC.swift │ ├── PopoverVC.swift │ ├── ProgressVC.swift │ ├── ResizeImageVC.swift │ ├── ScreenshotVC.swift │ ├── ScrollViewVC.swift │ ├── SearchBarVC.swift │ ├── SecondScreenVC.swift │ ├── SectionCollectionViewVC.swift │ ├── SectionTableViewVC.swift │ ├── SegmentedControlVC.swift │ ├── SlideTableViewVC.swift │ ├── SliderVC.swift │ ├── StepperVC.swift │ ├── SwitchVC.swift │ ├── SynchronizeScrollViewVC.swift │ ├── TextCheckerVC.swift │ ├── TextFieldVC.swift │ ├── TextViewVC.swift │ ├── ToggleTouchVC.swift │ ├── ToolBarVC.swift │ ├── TransformImageViewVC.swift │ ├── TransitionsViewVC.swift │ ├── TransparencyImageVC.swift │ ├── UIBezierPath │ │ ├── BezierPathVC.swift │ │ ├── DrawCircleView.swift │ │ ├── DrawLineView.swift │ │ └── DrawRectangleView.swift │ ├── UINavigationBar │ │ ├── FirstNavigationVC.swift │ │ └── SecondNavigationVC.swift │ ├── UINavigationViewController │ │ ├── FirstViewController.swift │ │ └── SecondViewController.swift │ ├── UITabBarController │ │ ├── FirstTabBarViewController.swift │ │ ├── RootTabBarViewController.swift │ │ └── SecondTabBarViewController.swift │ ├── UiViewController │ │ ├── PushFirstVC.swift │ │ └── PushSecondVC.swift │ ├── UserNotificationVC.swift │ ├── WebPdfFileVC.swift │ ├── WebPdfVC.swift │ ├── WebViewVC.swift │ └── WindowVC.swift ├── RootViewController.swift ├── Support │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── BaseViewController.swift │ ├── Info.plist │ ├── UIKit_component_handling.xcdatamodeld │ │ └── UIKit_component_handling.xcdatamodel │ │ │ └── contents │ ├── apple.png │ ├── iOS_Security_Guide.pdf │ └── vertical.jpeg ├── UIKit component handling.entitlements ├── UIKit component handling.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── thyeon.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── thyeon.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist ├── UIKit component handling │ ├── AppDelegate.swift │ ├── ComponentViewController │ │ ├── ButtonViewController.swift │ │ └── LabelViewController.swift │ └── Support │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── RootViewController.swift │ │ └── UIKit_component_handling.xcdatamodeld │ │ └── UIKit_component_handling.xcdatamodel │ │ └── contents ├── UIKit component handlingTests │ ├── Info.plist │ └── UIKit_component_handlingTests.swift └── UIKit component handlingUITests │ ├── Info.plist │ └── UIKit_component_handlingUITests.swift ├── UIKit component handlingTests ├── Info.plist └── UIKit_component_handlingTests.swift └── UIKit component handlingUITests ├── Info.plist └── UIKit_component_handlingUITests.swift /README.md: -------------------------------------------------------------------------------- 1 | # UIKit-component 2 | Sharing the handling of components in UIKit 3 | 4 | ## Preview 5 | 2018-08-22 9 55 55 6 | 7 | ## List 8 | - UILabel 9 | - UIButton 10 | - Various UIButtons 11 | - UITextField 12 | - UIImageView 13 | - UIFont 14 | - UserNotification 15 | - UIWebView 16 | - UIAlertController 17 | - UIPickerView 18 | - UINavigationController 19 | - UITabBarController 20 | - UIImage (Transform) 21 | - PushViewController 22 | - UIScrollView 23 | - UIBarButtonItem 24 | - UIPageControl 25 | - UITableView Section 26 | - UITextView 27 | - UISlider 28 | - UISwitch 29 | - UIDatePicker 30 | - UIActivityIndicator 31 | - UISearchBar 32 | - UIWindow 33 | - UIToolBar 34 | - UIProgressView 35 | - UISegmentedControl 36 | - UIStepper 37 | - UINavigationBar 38 | - ActionSheet 39 | - MenuItem 40 | - UIMotionEffect 41 | - UIVisualEffectView 42 | - TransitionsView 43 | - ToggleTouchEvent 44 | - Limited UITextField 45 | - Password UITextField 46 | - GestureRecognizer 47 | - Password UIAlertViewController 48 | - Character limit UIAlertViewController 49 | - Effect processing 50 | - Second screen 51 | - Extending button UITableView 52 | - Slide UITableView 53 | - Synchronize UIScrollView 54 | - Animate UIButton 55 | - Customize UIButton 56 | - Delete UI parts 57 | - Add/Delete UITableView 58 | - UIBezierPath 59 | - UICollectionView 60 | - UICollectionView Customize 61 | - UICollectionView Section 62 | - UIImagePickerController 63 | - Transparency of images 64 | - Resize UIImage 65 | - Composing UIImage 66 | - Screenshot 67 | - UIPopoverController 68 | - UITextChecker 69 | - Attachment UIView 70 | - Gravity UIView 71 | - UIView animation summary 72 | - Dragging UIView 73 | - Make multiple UIButtons 74 | - Hide/Show UIView 75 | - Open PDF with UIWebView 76 | - Open local PDF with UIWebView 77 | -------------------------------------------------------------------------------- /UIKit component handling.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIKit component handling.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /UIKit component handling.xcodeproj/project.xcworkspace/xcuserdata/thyeon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calmone/iOS-UIKit-component/9cceb502876d3cc16faebb4661956e101930bc2d/UIKit component handling.xcodeproj/project.xcworkspace/xcuserdata/thyeon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /UIKit component handling.xcodeproj/xcuserdata/thyeon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /UIKit component handling.xcodeproj/xcuserdata/thyeon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UIKit component handling.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 6B971EE1210AFF63009390B8 16 | 17 | primary 18 | 19 | 20 | 6B971EF8210AFF64009390B8 21 | 22 | primary 23 | 24 | 25 | 6B971F03210AFF64009390B8 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /UIKit component handling/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var effectView: UIView! 16 | var window: UIWindow? 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 19 | // Override point for customization after application launch. 20 | return true 21 | } 22 | 23 | func applicationWillResignActive(_ application: UIApplication) { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 26 | makeEffectView() 27 | } 28 | 29 | func applicationDidEnterBackground(_ application: UIApplication) { 30 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 31 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 32 | } 33 | 34 | func applicationWillEnterForeground(_ application: UIApplication) { 35 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 36 | } 37 | 38 | func applicationDidBecomeActive(_ application: UIApplication) { 39 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 40 | removeEffectView() 41 | } 42 | 43 | func applicationWillTerminate(_ application: UIApplication) { 44 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 45 | // Saves changes in the application's managed object context before the application terminates. 46 | } 47 | 48 | } 49 | 50 | extension AppDelegate { 51 | 52 | private func makeEffectView() { 53 | let effect: UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.light) 54 | effectView = UIVisualEffectView(effect: effect) 55 | effectView.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height) 56 | self.window?.addSubview(effectView) 57 | } 58 | 59 | private func removeEffectView() { 60 | if effectView != nil { 61 | self.effectView.removeFromSuperview() 62 | } 63 | } 64 | 65 | // Add UIAlertController on UIViewController 66 | func showAlert(vc: UIViewController, title: String, message: String, actionTitle: String, actionStyle: UIAlertActionStyle) { 67 | // Create a UIAlertController. 68 | let alert: UIAlertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 69 | 70 | // Create an action of OK. 71 | let action = UIAlertAction(title: actionTitle, style: actionStyle) { action in 72 | print("Action OK!!") 73 | } 74 | 75 | // Add an Action of OK. 76 | alert.addAction(action) 77 | 78 | // Activate UIAlert. 79 | vc.present(alert, animated: true, completion: nil) 80 | } 81 | 82 | // Add ActionSheet display with UIAlertController on UIViewController 83 | func showActionSheetAlert(vc: UIViewController, title: String, message: String, actions: [UIAlertAction]) { 84 | // Create a UIAlertController. 85 | let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.actionSheet) 86 | 87 | // Add action. 88 | for action in actions { 89 | alert.addAction(action) 90 | } 91 | 92 | // Activate UIAlert. 93 | vc.present(alert, animated: true, completion: nil) 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ActionSheetVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ActionSheetVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ActionSheetVC: BaseViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Generate action. 19 | let action_1 = UIAlertAction(title: "Hello", style: UIAlertActionStyle.default) { (_) in 20 | print("Hello") 21 | } 22 | let action_2 = UIAlertAction(title: "yes", style: UIAlertActionStyle.default) { (_) in 23 | print("yes") 24 | } 25 | let action_3 = UIAlertAction(title: "no", style: UIAlertActionStyle.default) { (_) in 26 | print("no") 27 | } 28 | 29 | let actionArray: [UIAlertAction] = [action_1, action_2, action_3] 30 | 31 | appDelegate()?.showActionSheetAlert(vc: self, title: "Title", message: "Message", actions: actionArray) 32 | } 33 | 34 | override func didReceiveMemoryWarning() { 35 | super.didReceiveMemoryWarning() 36 | // Dispose of any resources that can be recreated. 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ActivityIndicatorVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ActivityIndicatorVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ActivityIndicatorVC: BaseViewController { 12 | 13 | lazy var activityIndicator: UIActivityIndicatorView = { 14 | // Create an indicator. 15 | let activityIndicator = UIActivityIndicatorView() 16 | activityIndicator.frame = CGRect(x: 0, y: 0, width: 50, height: 50) 17 | activityIndicator.center = self.view.center 18 | 19 | // Also show the indicator even when the animation is stopped. 20 | activityIndicator.hidesWhenStopped = false 21 | activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.white 22 | 23 | // Start animation. 24 | activityIndicator.startAnimating() 25 | 26 | return activityIndicator 27 | }() 28 | 29 | lazy var button: UIButton = { 30 | // Create a button. 31 | let button = UIButton(frame: CGRect(x:0, y:0, width:60, height:60)) 32 | button.backgroundColor = UIColor.red 33 | button.layer.masksToBounds = true 34 | button.layer.cornerRadius = 30.0 35 | button.setTitle("Stop", for: .normal) 36 | button.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-50) 37 | button.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 38 | 39 | return button 40 | }() 41 | 42 | override func viewDidLoad() { 43 | super.viewDidLoad() 44 | 45 | // Do any additional setup after loading the view. 46 | 47 | // Set the background color to black. 48 | self.view.backgroundColor = UIColor.black 49 | 50 | // Add UIActivityIndicatorView on view 51 | self.view.addSubview(self.activityIndicator) 52 | 53 | // Add UIButton on view 54 | self.view.addSubview(self.button) 55 | } 56 | 57 | override func didReceiveMemoryWarning() { 58 | super.didReceiveMemoryWarning() 59 | // Dispose of any resources that can be recreated. 60 | } 61 | 62 | // Button event. 63 | @objc func onClickButton(sender: UIButton){ 64 | 65 | if self.activityIndicator.isAnimating { 66 | self.activityIndicator.stopAnimating() 67 | self.button.setTitle("Start", for: .normal) 68 | self.button.backgroundColor = UIColor.blue 69 | } 70 | else { 71 | self.activityIndicator.startAnimating() 72 | self.button.setTitle("Stop", for: .normal) 73 | self.button.backgroundColor = UIColor.red 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/AlertVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AlertVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 2.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AlertVC: BaseViewController { 12 | 13 | // Generate UIButton. 14 | lazy var button: UIButton = { 15 | let button: UIButton = UIButton() 16 | let width: CGFloat = 250 17 | let height: CGFloat = 50 18 | let posX: CGFloat = (self.view.bounds.width - width)/2 19 | let posY: CGFloat = 250 20 | 21 | button.frame = CGRect(x: posX, y: posY, width: width, height: height) 22 | button.backgroundColor = UIColor.red 23 | button.layer.masksToBounds = true 24 | button.layer.cornerRadius = 20.0 25 | button.setTitle("Show UIAlert", for: .normal) 26 | button.setTitleColor(UIColor.white, for: .normal) 27 | button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside) 28 | 29 | return button 30 | }() 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | // Do any additional setup after loading the view. 36 | 37 | // Add UIButton on view 38 | self.view.addSubview(self.button) 39 | } 40 | 41 | override func didReceiveMemoryWarning() { 42 | super.didReceiveMemoryWarning() 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | // Button event 47 | @objc private func buttonPressed(_ sender: Any) { 48 | appDelegate()?.showAlert(vc: self, title: "Title", message: "Message", actionTitle: "OK", actionStyle: .default) 49 | } 50 | 51 | // Add UIAlertController on UIViewController 52 | // This function in Appdelegate 53 | // func showAlert(vc: UIViewController, title: String, message: String, actionTitle: String, actionStyle: UIAlertActionStyle) { 54 | // // Create a UIAlertController. 55 | // let alert: UIAlertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 56 | // 57 | // // Create an action of OK. 58 | // let action = UIAlertAction(title: actionTitle, style: actionStyle) { action in 59 | // print("Action OK!!") 60 | // } 61 | // 62 | // // Add an Action of OK. 63 | // alert.addAction(action) 64 | // 65 | // // Activate UIAlert. 66 | // vc.present(alert, animated: true, completion: nil) 67 | // } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/AnimateButtonVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AnimateButtonVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AnimateButtonVC: BaseViewController { 12 | 13 | lazy var button: UIButton = { 14 | // Generate Button. 15 | let b = UIButton() 16 | b.frame = CGRect(x: 0, y: 0, width: 100, height: 100) 17 | b.backgroundColor = UIColor.green 18 | b.layer.masksToBounds = true 19 | b.setTitle("button", for: UIControlState.normal) 20 | b.setTitleColor(UIColor.white, for: UIControlState.normal) 21 | b.layer.cornerRadius = 50.0 22 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 23 | 24 | // Add an event at TouchDown. 25 | b.addTarget(self, action: #selector(onDownButton(sender:)), for: .touchDown) 26 | 27 | // Add an event at TouchUp. 28 | b.addTarget(self, action: #selector(onUpButton(sender:)), for: [.touchUpInside, .touchUpOutside]) 29 | 30 | return b 31 | }() 32 | 33 | override func viewDidLoad() { 34 | super.viewDidLoad() 35 | 36 | // Do any additional setup after loading the view. 37 | 38 | // Add button on view 39 | self.view.addSubview(button) 40 | } 41 | 42 | override func didReceiveMemoryWarning() { 43 | super.didReceiveMemoryWarning() 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | // Button event (Down) 48 | @objc func onDownButton(sender: UIButton){ 49 | //UIView.animateWithDuration 50 | UIView.animate(withDuration: 0.06, 51 | // Processing during animation. 52 | animations: { () -> Void in 53 | // Create an affine matrix for reduction. 54 | self.button.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) 55 | }) 56 | { (Bool) -> Void in 57 | 58 | } 59 | } 60 | 61 | // Button event (Up) 62 | @objc func onUpButton(sender: UIButton){ 63 | UIView.animate(withDuration: 0.1, 64 | // Processing during animation. 65 | animations: { () -> Void in 66 | // Create an affine matrix for magnification. 67 | self.button.transform = CGAffineTransform(scaleX: 0.4, y: 0.4) 68 | // Create an affine matrix for reduction. 69 | self.button.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) 70 | }) 71 | { (Bool) -> Void in 72 | 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/AttachmentVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AttachmentVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AttachmentVC: BaseViewController { 12 | 13 | // Generate button. 14 | lazy var button: UIButton = { 15 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 16 | b.layer.position = self.view.center 17 | b.layer.masksToBounds = true 18 | b.layer.cornerRadius = 20.0 19 | b.setTitleColor(UIColor.white, for: UIControlState.normal) 20 | b.setTitleColor(UIColor.black, for: UIControlState.highlighted) 21 | b.backgroundColor = UIColor.red 22 | b.setTitle("Dropped!", for: UIControlState.normal) 23 | b.addTarget(self, action: #selector(onClickButton(_:)), for: UIControlEvents.touchUpInside) 24 | 25 | return b 26 | }() 27 | 28 | // Generate view. 29 | lazy var springView: UIView = { 30 | let v = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: 50)) 31 | v.layer.position = self.view.center 32 | v.backgroundColor = UIColor.brown 33 | 34 | return v 35 | }() 36 | 37 | 38 | // You must save the instance of UIDynamicAnimator and the animation will not run. 39 | var animator : UIDynamicAnimator! 40 | var gravity : UIGravityBehavior! 41 | 42 | override func viewDidLoad() { 43 | super.viewDidLoad() 44 | 45 | // Do any additional setup after loading the view. 46 | 47 | // Add button on view 48 | self.view.addSubview(button) 49 | 50 | // Add springView on view 51 | self.view.addSubview(springView) 52 | 53 | // Generate UIDynamicAnimator and save instance. 54 | animator = UIDynamicAnimator(referenceView: self.view) 55 | 56 | // Generate gravity and attach it to Button. 57 | gravity = UIGravityBehavior(items: [button]) 58 | 59 | // Generate attachment. 60 | let attach = UIAttachmentBehavior(item: button, attachedToAnchor: self.view.center) 61 | 62 | // Attenuation value. 63 | attach.damping = 0.01 64 | 65 | // Amplitude. 66 | attach.frequency = 1.0 67 | 68 | // The length of the string. 69 | attach.length = 100 70 | 71 | // Set the block statement called when the animation is moving. 72 | attach.action = { 73 | var rect = self.springView.frame 74 | rect.size.height = self.button.frame.origin.y - rect.origin.y 75 | self.springView.frame = rect 76 | } 77 | 78 | // Added attach to UIDynamicAnimator. 79 | animator.addBehavior(attach) 80 | } 81 | 82 | override func didReceiveMemoryWarning() { 83 | super.didReceiveMemoryWarning() 84 | // Dispose of any resources that can be recreated. 85 | } 86 | 87 | // A method called when a Button is pressed. 88 | @objc private func onClickButton(_ sender : UIButton){ 89 | // Added gravity to UIDynamicAnimator. 90 | animator.addBehavior(gravity) 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/BarButtonItemVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BarButtonItemVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 7.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class BarButtonItemVC: UIViewController { 12 | 13 | // Create left UIBarButtonItem. 14 | lazy var leftButton: UIBarButtonItem = { 15 | let button = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(buttonPressed(_:))) 16 | button.tag = 1 17 | 18 | return button 19 | }() 20 | 21 | // Create right UIBarButtonItem. 22 | lazy var rightButton: UIBarButtonItem = { 23 | let button = UIBarButtonItem(title: "RightBtn", style: .plain, target: self, action: #selector(buttonPressed(_:))) 24 | button.tag = 2 25 | 26 | return button 27 | }() 28 | 29 | // Create back button. 30 | lazy var backButton: UIButton = { 31 | let button = UIButton(frame: CGRect(x: 0, y: self.view.frame.size.height/2, width: self.view.frame.size.width, height: 100)) 32 | button.setTitle("back", for: .normal) 33 | button.backgroundColor = UIColor.brown 34 | button.addTarget(self, action: #selector(backButtonPressed(_:)), for: .touchUpInside) 35 | 36 | return button 37 | }() 38 | 39 | override func viewDidLoad() { 40 | super.viewDidLoad() 41 | 42 | // Do any additional setup after loading the view. 43 | 44 | // Set the background color to Green. 45 | self.view.backgroundColor = .green 46 | 47 | // Set the title of NavigationController. 48 | self.navigationItem.prompt = "navigationVC" 49 | 50 | // Set it to the left of the navigation bar. 51 | self.navigationItem.leftBarButtonItem = self.leftButton 52 | 53 | // Set it to the right of the navigation bar. 54 | self.navigationItem.rightBarButtonItem = self.rightButton 55 | 56 | // Add back button on view 57 | self.view.addSubview(self.backButton) 58 | } 59 | 60 | override func didReceiveMemoryWarning() { 61 | super.didReceiveMemoryWarning() 62 | // Dispose of any resources that can be recreated. 63 | } 64 | 65 | // Button event. 66 | @objc private func buttonPressed(_ sender: Any) { 67 | if let button = sender as? UIBarButtonItem { 68 | switch button.tag { 69 | case 1: 70 | // Change the background color to blue. 71 | self.view.backgroundColor = .blue 72 | case 2: 73 | // Change the background color to red. 74 | self.view.backgroundColor = .red 75 | default: 76 | print("error") 77 | } 78 | } 79 | } 80 | 81 | @objc private func backButtonPressed(_ sender: Any) { 82 | self.navigationController?.popViewController(animated: true) 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/BlurEffectVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BlurEffectVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class BlurEffectVC: BaseViewController { 12 | 13 | private var effectView: UIVisualEffectView! 14 | 15 | lazy var segcontrol: UISegmentedControl = { 16 | // Generate SegmentedControl. 17 | let sc: UISegmentedControl = UISegmentedControl(items: ["Dark", "Light", "ExtraLight"]) 18 | sc.center = CGPoint(x: self.view.center.x, y: self.view.bounds.maxY - 50) 19 | sc.backgroundColor = UIColor.gray 20 | sc.tintColor = UIColor.white 21 | sc.addTarget(self, action: #selector(onClickSegmentedControl(sender:)), for: UIControlEvents.valueChanged) 22 | 23 | return sc 24 | }() 25 | 26 | lazy var imageView: UIImageView = { 27 | // Generate background image. 28 | let image = UIImage(named: "vertical.jpeg") 29 | let iv = UIImageView(frame: self.view.bounds) 30 | iv.image = image 31 | 32 | return iv 33 | }() 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | 38 | // Do any additional setup after loading the view. 39 | 40 | // Add iamgeView on view 41 | self.view.addSubview(self.imageView) 42 | 43 | // Add segmentedControl on view 44 | self.view.addSubview(self.segcontrol) 45 | } 46 | 47 | override func didReceiveMemoryWarning() { 48 | super.didReceiveMemoryWarning() 49 | // Dispose of any resources that can be recreated. 50 | } 51 | 52 | // Apply the effect. 53 | func addVirtualEffectView(effect : UIBlurEffect!){ 54 | 55 | if effectView != nil { 56 | effectView.removeFromSuperview() 57 | } 58 | 59 | // Create EffectView to apply Blur effect. 60 | effectView = UIVisualEffectView(effect: effect) 61 | effectView.frame = CGRect(x: 0, y: 0, width: 200, height: 400) 62 | effectView.layer.position = CGPoint(x: self.segcontrol.bounds.midX, y: -(effectView.frame.midY + 20) ) 63 | effectView.layer.masksToBounds = true 64 | effectView.layer.cornerRadius = 20.0 65 | self.segcontrol.addSubview(effectView) 66 | } 67 | 68 | // The method to be called when the value of SegmentedControl has changed. 69 | @objc func onClickSegmentedControl(sender : UISegmentedControl){ 70 | 71 | var effect : UIBlurEffect! 72 | 73 | switch sender.selectedSegmentIndex { 74 | case 0: 75 | // Create a dark Blur effect. 76 | effect = UIBlurEffect(style: UIBlurEffectStyle.dark) 77 | case 1: 78 | // Create a light Blur effect. 79 | effect = UIBlurEffect(style: UIBlurEffectStyle.light) 80 | case 2: 81 | // Create a extra light Blur effect. 82 | effect = UIBlurEffect(style: UIBlurEffectStyle.extraLight) 83 | default: return 84 | } 85 | 86 | self.addVirtualEffectView(effect: effect) 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ButtonVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ButtonVC: BaseViewController { 12 | 13 | lazy var button: UIButton = { 14 | let button = UIButton() 15 | 16 | // Define the size of the button. 17 | let width: CGFloat = 300 18 | let height: CGFloat = 100 19 | 20 | // Define coordinates to be placed. 21 | // (center of screen) 22 | let posX: CGFloat = self.view.bounds.width/2 - width/2 23 | let posY: CGFloat = self.view.bounds.height/2 - height/2 24 | 25 | // Set the button installation coordinates and size. 26 | button.frame = CGRect(x: posX, y: posY, width: width, height: height) 27 | 28 | // Set the background color of the button. 29 | button.backgroundColor = .orange 30 | 31 | // Round the button frame. 32 | button.layer.masksToBounds = true 33 | 34 | // Set the radius of the corner. 35 | button.layer.cornerRadius = 20.0 36 | 37 | // Set the title (normal). 38 | button.setTitle("Button (Normal)", for: .normal) 39 | button.setTitleColor(.white, for: .normal) 40 | 41 | // Set the title (highlighted). 42 | button.setTitle("Button (highlighted)", for: .highlighted) 43 | button.setTitleColor(.black, for: .highlighted) 44 | 45 | // Tag a button. 46 | button.tag = 1 47 | 48 | // Add an event. 49 | button.addTarget(self, action: #selector(onClickMyButton(_:)), for: .touchUpInside) 50 | 51 | return button 52 | }() 53 | 54 | override func viewDidLoad() { 55 | super.viewDidLoad() 56 | 57 | // Do any additional setup after loading the view. 58 | 59 | // Add UIButton to view. 60 | self.view.addSubview(self.button) 61 | } 62 | 63 | override func didReceiveMemoryWarning() { 64 | super.didReceiveMemoryWarning() 65 | // Dispose of any resources that can be recreated. 66 | } 67 | 68 | // Button event. 69 | @objc internal func onClickMyButton(_ sender: Any) { 70 | if let button = sender as? UIButton { 71 | print("onClickButton"); 72 | print("button.currentTitle: \((button.currentTitle) ?? "Empty")") 73 | print("button.tag: \(button.tag)") 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ButtonsVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonsVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 30.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ButtonsVC: BaseViewController { 12 | 13 | lazy var infoDarkButton: UIButton = { 14 | // Generate button. 15 | let button = UIButton(type: .infoDark) 16 | 17 | // Specify the position of the button. 18 | button.layer.position = CGPoint(x: self.view.frame.width/2, y: 200) 19 | 20 | // Tag a button. 21 | button.tag = 1 22 | 23 | // Add an event. 24 | button.addTarget(self, action: #selector(onClickButtons(_:)), for: .touchUpInside) 25 | return button 26 | }() 27 | 28 | lazy var infoLightButton: UIButton = { 29 | // Generate button. 30 | let button = UIButton(type: .infoLight) 31 | 32 | // Specify the position of the button. 33 | button.layer.position = CGPoint(x: self.view.frame.width/2, y: 250) 34 | 35 | // Tag a button. 36 | button.tag = 2 37 | 38 | // Add an event. 39 | button.addTarget(self, action: #selector(onClickButtons(_:)), for: .touchUpInside) 40 | return button 41 | }() 42 | 43 | lazy var addButton: UIButton = { 44 | // Generate button. 45 | let button = UIButton(type: .contactAdd) 46 | 47 | // Specify the position of the button. 48 | button.layer.position = CGPoint(x: self.view.frame.width/2, y: 300) 49 | 50 | // Tag a button. 51 | button.tag = 3 52 | 53 | // Add an event. 54 | button.addTarget(self, action: #selector(onClickButtons(_:)), for: .touchUpInside) 55 | return button 56 | }() 57 | 58 | lazy var detailButton: UIButton = { 59 | // Generate button. 60 | let button = UIButton(type: .detailDisclosure) 61 | 62 | // Specify the position of the button. 63 | button.layer.position = CGPoint(x: self.view.frame.width/2, y: 350) 64 | 65 | // Tag a button. 66 | button.tag = 4 67 | 68 | // Add an event. 69 | button.addTarget(self, action: #selector(onClickButtons(_:)), for: .touchUpInside) 70 | return button 71 | }() 72 | 73 | lazy var systemButton: UIButton = { 74 | // Generate button. 75 | let button = UIButton(type: .system) 76 | 77 | // Define the size of the button. 78 | let width: CGFloat = 200 79 | let height: CGFloat = 50 80 | 81 | // Specify the position of the button. 82 | let posX: CGFloat = self.view.frame.width/2 - width/2 83 | let posY: CGFloat = 400 84 | 85 | // Tag a button. 86 | button.tag = 5 87 | 88 | // Set the button installation coordinates and size. 89 | button.frame = CGRect(x: posX, y: posY, width: width, height: height) 90 | 91 | // Set the title (normal). 92 | button.setTitle("systemButton", for: .normal) 93 | 94 | // Add an event. 95 | button.addTarget(self, action: #selector(onClickButtons(_:)), for: .touchUpInside) 96 | return button 97 | }() 98 | 99 | override func viewDidLoad() { 100 | super.viewDidLoad() 101 | 102 | // Do any additional setup after loading the view. 103 | 104 | // Add UIButtons to view. 105 | self.view.addSubview(self.infoDarkButton) 106 | self.view.addSubview(self.infoLightButton) 107 | self.view.addSubview(self.addButton) 108 | self.view.addSubview(self.detailButton) 109 | self.view.addSubview(self.systemButton) 110 | } 111 | 112 | override func didReceiveMemoryWarning() { 113 | super.didReceiveMemoryWarning() 114 | // Dispose of any resources that can be recreated. 115 | } 116 | 117 | // Button event. 118 | @objc private func onClickButtons(_ sender: Any) { 119 | if let button = sender as? UIButton { 120 | print("onClickButton"); 121 | print("button.currentTitle: \((button.currentTitle) ?? "Empty")") 122 | print("button.tag: \(button.tag)") 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/CharacterLimitAlertVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CharacterLimitAlertVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 13.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CharacterLimitAlertVC: BaseViewController, UITextFieldDelegate { 12 | 13 | // Generate Button. 14 | lazy var button: UIButton = { 15 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 40)) 16 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: 200) 17 | b.layer.cornerRadius = 20.0 18 | b.backgroundColor = UIColor.red 19 | b.setTitle("Start UIAlert", for: .normal) 20 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 21 | 22 | return b 23 | }() 24 | 25 | var InputStr:String! 26 | 27 | // The maximum number of characters that can be input. 28 | let maxLength: Int = 6 29 | 30 | override func viewDidLoad() { 31 | super.viewDidLoad() 32 | 33 | // Do any additional setup after loading the view. 34 | 35 | // Add button on view 36 | self.view.addSubview(button) 37 | } 38 | 39 | override func didReceiveMemoryWarning() { 40 | super.didReceiveMemoryWarning() 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | @objc private func onClickButton(sender: UIButton) { 45 | // Alert generation. 46 | let alert: UIAlertController = UIAlertController(title: "title", message: "Enter up to 6 characters", preferredStyle: UIAlertControllerStyle.alert) 47 | 48 | // Cancel action generation. 49 | let CancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.destructive) { (action: UIAlertAction!) -> Void in 50 | print("Cancel") 51 | } 52 | 53 | // OK action generation. 54 | let OkAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (action: UIAlertAction!) -> Void in 55 | print("OK") 56 | } 57 | 58 | // Add a TextField to the Alert. 59 | alert.addTextField { (textField: UITextField!) -> Void in 60 | // Set delegate 61 | textField.delegate = self 62 | } 63 | 64 | // Add an action to Alert. 65 | alert.addAction(OkAction) 66 | alert.addAction(CancelAction) 67 | 68 | // Activate Alert. 69 | present(alert, animated: true, completion: nil) 70 | } 71 | 72 | // Called when text is edited. 73 | func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 74 | // Limit input when the input character exceeds 6 characters. 75 | if range.location < maxLength { 76 | textField.isEnabled = true 77 | // Display the input characters. 78 | print(textField.text!) 79 | return true 80 | } else { 81 | textField.isEnabled = false 82 | print("More than 6 characters") 83 | return false 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/CollectionViewCellVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionViewCellVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 17.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CollectionViewCellVC: BaseViewController { 12 | 13 | lazy var collectionView: UICollectionView = { 14 | // Generate layout of CollectionView. 15 | let layout = UICollectionViewFlowLayout() 16 | 17 | // The size of each Cell. 18 | layout.itemSize = CGSize(width:50, height:50) 19 | 20 | // Margin of Cell. 21 | layout.sectionInset = UIEdgeInsetsMake(16, 16, 32, 16) 22 | 23 | // Header size per section. 24 | layout.headerReferenceSize = CGSize(width:100,height:30) 25 | 26 | // Generate CollectionView. 27 | let cv = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) 28 | 29 | // Register the class used for Cell. 30 | cv.register(CustomUICollectionViewCell.self, forCellWithReuseIdentifier: "CollectionCell") 31 | 32 | cv.delegate = self 33 | cv.dataSource = self 34 | 35 | return cv 36 | }() 37 | 38 | override func viewDidLoad() { 39 | super.viewDidLoad() 40 | 41 | // Do any additional setup after loading the view. 42 | 43 | // Add collectionView on view 44 | self.view.addSubview(collectionView) 45 | } 46 | 47 | override func didReceiveMemoryWarning() { 48 | super.didReceiveMemoryWarning() 49 | // Dispose of any resources that can be recreated. 50 | } 51 | 52 | } 53 | 54 | extension CollectionViewCellVC: UICollectionViewDelegate, UICollectionViewDataSource { 55 | 56 | // Called when Cell is selected 57 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 58 | 59 | print("Num: \(indexPath.row)") 60 | 61 | } 62 | 63 | // Returns the total number of Cells 64 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 65 | return 100 66 | } 67 | 68 | // Set a value in Cell 69 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 70 | let cell : CustomUICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! CustomUICollectionViewCell 71 | cell.configure(text: indexPath.row.description) 72 | 73 | return cell 74 | } 75 | 76 | } 77 | 78 | fileprivate class CustomUICollectionViewCell : UICollectionViewCell { 79 | 80 | var textLabel : UILabel? 81 | 82 | required init(coder aDecoder: NSCoder) { 83 | super.init(coder: aDecoder)! 84 | } 85 | 86 | override init(frame: CGRect) { 87 | super.init(frame: frame) 88 | } 89 | 90 | func configure(text: String) { 91 | // Generate UILabel. 92 | textLabel = UILabel(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height)) 93 | textLabel?.text = text 94 | textLabel?.backgroundColor = UIColor.white 95 | textLabel?.textAlignment = NSTextAlignment.center 96 | 97 | // Added to Cell. 98 | self.contentView.addSubview(textLabel!) 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/CollectionViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 17.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CollectionViewVC: BaseViewController { 12 | 13 | lazy var collectionView: UICollectionView = { 14 | // Generate layout of CollectionView. 15 | let layout = UICollectionViewFlowLayout() 16 | 17 | // The size of each Cell. 18 | layout.itemSize = CGSize(width:50, height:50) 19 | 20 | // Margin of Cell. 21 | layout.sectionInset = UIEdgeInsetsMake(16, 16, 32, 16) 22 | 23 | // Header size per section. 24 | layout.headerReferenceSize = CGSize(width:100,height:30) 25 | 26 | // Generate CollectionView. 27 | let cv = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) 28 | 29 | // Register the class used for Cell. 30 | cv.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "CollectionCell") 31 | 32 | cv.delegate = self 33 | cv.dataSource = self 34 | 35 | return cv 36 | }() 37 | 38 | override func viewDidLoad() { 39 | super.viewDidLoad() 40 | 41 | // Do any additional setup after loading the view. 42 | 43 | // Add collectionView on view 44 | self.view.addSubview(collectionView) 45 | } 46 | 47 | override func didReceiveMemoryWarning() { 48 | super.didReceiveMemoryWarning() 49 | // Dispose of any resources that can be recreated. 50 | } 51 | 52 | } 53 | 54 | extension CollectionViewVC: UICollectionViewDelegate, UICollectionViewDataSource { 55 | 56 | // Called when Cell is selected 57 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 58 | 59 | print("Num: \(indexPath.row)") 60 | print("Value:\(collectionView)") 61 | 62 | } 63 | 64 | // Returns the total number of Cells 65 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 66 | return 100 67 | } 68 | 69 | // Set a value in Cell 70 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 71 | let cell : UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath as IndexPath) 72 | cell.backgroundColor = UIColor.orange 73 | 74 | return cell 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ComposingImageVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ComposingImageVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 20.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ComposingImageVC: BaseViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Make the first UIImage. 19 | var image_1 = UIImage(named: "vertical.jpeg")! 20 | 21 | // Resize. 22 | image_1 = image_1.ResizeUIImage(width: self.view.frame.maxX, height: self.view.frame.maxY) 23 | 24 | // Make a second UIImage. 25 | var image_2 = UIImage(named: "apple.png")! 26 | 27 | // Resize. 28 | image_2 = image_2.ResizeUIImage(width: self.view.frame.midX, height: self.view.frame.midY) 29 | 30 | // Composite images. 31 | let ComposedImage = UIImage.ComposeUIImage(UIImageArray: [image_1, image_2], width: self.view.frame.maxX, height: self.view.frame.maxY) 32 | 33 | // Specify the UIImage synthesized in UIImageView. 34 | let myImageView = UIImageView(image: ComposedImage) 35 | 36 | self.view.addSubview(myImageView) 37 | } 38 | 39 | override func didReceiveMemoryWarning() { 40 | super.didReceiveMemoryWarning() 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | } 45 | 46 | fileprivate extension UIImage { 47 | 48 | // Create a class method of Resize. 49 | func ResizeUIImage(width: CGFloat, height: CGFloat) -> UIImage! { 50 | 51 | // Prepare the context of the specified image size. 52 | UIGraphicsBeginImageContext(CGSize(width: width, height: height)) 53 | 54 | // Draw the image in the context. 55 | self.draw(in: CGRect(x: 0, y: 0, width: width, height: height)) 56 | 57 | // Create a UIImage from the context. 58 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 59 | 60 | // Close the context. 61 | UIGraphicsEndImageContext() 62 | 63 | return newImage 64 | } 65 | 66 | // Class method to synthesize images. 67 | class func ComposeUIImage(UIImageArray : [UIImage], width: CGFloat, height : CGFloat) -> UIImage! { 68 | 69 | // Prepare the context of the specified image size. 70 | UIGraphicsBeginImageContext(CGSize(width: width, height: height)) 71 | 72 | // Turn it by the amount of UIImage. 73 | for image: UIImage in UIImageArray { 74 | // Draw the image in the context. 75 | image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)) 76 | } 77 | 78 | // Create a UIImage from the context. 79 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 80 | 81 | // Close the context. 82 | UIGraphicsEndImageContext() 83 | 84 | return newImage 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/DatePickerVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DatePickerVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DatePickerVC: BaseViewController { 12 | 13 | lazy var textField: UITextField = { 14 | // Create a UITextField. 15 | let textField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) 16 | textField.text = "" 17 | textField.borderStyle = UITextBorderStyle.roundedRect 18 | textField.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height - 100) 19 | 20 | return textField 21 | }() 22 | 23 | lazy var datePicker: UIDatePicker = { 24 | // Set datePicker (default is the position at the top of the screen). 25 | let datePicker = UIDatePicker(frame: CGRect(x: 0, y: 150, width: self.view.frame.width, height: 200)) 26 | datePicker.timeZone = NSTimeZone.local 27 | datePicker.backgroundColor = UIColor.white 28 | datePicker.layer.cornerRadius = 5.0 29 | datePicker.layer.shadowOpacity = 0.5 30 | 31 | // Register the event when the value changed. 32 | datePicker.addTarget(self, action: #selector(onDidChangeDate(sender:)), for: .valueChanged) 33 | 34 | return datePicker 35 | }() 36 | 37 | override func viewDidLoad() { 38 | super.viewDidLoad() 39 | 40 | // Do any additional setup after loading the view. 41 | 42 | // Add UITextField on view 43 | self.view.addSubview(self.textField) 44 | 45 | // Add UIDatePicker 46 | self.view.addSubview(self.datePicker) 47 | } 48 | 49 | override func didReceiveMemoryWarning() { 50 | super.didReceiveMemoryWarning() 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | // Called when DatePicker is elected. 55 | @objc func onDidChangeDate(sender: UIDatePicker){ 56 | // Generate the format. 57 | let dateFormatter: DateFormatter = DateFormatter() 58 | dateFormatter.dateFormat = "yyyy/MM/dd hh:mm" 59 | 60 | // Obtain the date according to the format. 61 | let selectedDate: String = dateFormatter.string(from: sender.date) 62 | self.textField.text = selectedDate 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/DeletePartsVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DeletePartsVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DeletePartsVC: BaseViewController { 12 | 13 | lazy var button: UIButton = { 14 | // Generate button. 15 | let b = UIButton(frame: CGRect(x: 50, y: 150, width: 100, height: 100)) 16 | b.setTitle("UIButton", for: UIControlState.normal) 17 | b.setTitleColor(UIColor.black, for: UIControlState.normal) 18 | b.backgroundColor = UIColor.green 19 | 20 | return b 21 | }() 22 | 23 | lazy var label: UILabel = { 24 | // Generate label. 25 | let l = UILabel(frame: CGRect(x: 50, y: 300, width: 100, height: 100)) 26 | l.text = "UILabel" 27 | l.textAlignment = .center 28 | l.textColor = UIColor.green 29 | l.backgroundColor = UIColor.red 30 | 31 | return l 32 | }() 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | 37 | // Do any additional setup after loading the view. 38 | 39 | // Add button on view 40 | self.view.addSubview(button) 41 | 42 | print("View:\(view.description)") 43 | 44 | let views = self.view.subviews 45 | for view in views { 46 | print("View:\(view.description)") 47 | 48 | if view == self.button { 49 | // Remove button after 1.5 seconds 50 | DispatchQueue.main.asyncAfter(deadline: .now()+1.5) { 51 | view.removeFromSuperview() 52 | self.view.addSubview(self.label) 53 | } 54 | } 55 | } 56 | } 57 | 58 | override func didReceiveMemoryWarning() { 59 | super.didReceiveMemoryWarning() 60 | // Dispose of any resources that can be recreated. 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/DisplayViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisplayViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DisplayViewVC: BaseViewController { 12 | 13 | // Generate displayView 14 | lazy var displayView: UIView = { 15 | let v = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) 16 | v.backgroundColor = UIColor.orange 17 | v.alpha = 0.5 18 | v.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 19 | v.isHidden = true 20 | 21 | return v 22 | }() 23 | 24 | // Generate displayButton 25 | lazy var displayButton: UIButton = { 26 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50)) 27 | b.backgroundColor = UIColor.red 28 | b.layer.cornerRadius = 20.0 29 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height-50) 30 | b.setTitle("Appear", for: .normal) 31 | b.setTitleColor(UIColor.white, for: .normal) 32 | b.addTarget(self, action: #selector(onClickButton(_:)), for: .touchUpInside) 33 | 34 | return b 35 | }() 36 | 37 | var flag: Bool! = false 38 | 39 | override func viewDidLoad() { 40 | super.viewDidLoad() 41 | 42 | // Do any additional setup after loading the view. 43 | 44 | // Add displayView on view 45 | self.view.addSubview(displayView) 46 | 47 | // Add displayButton on view 48 | self.view.addSubview(displayButton) 49 | } 50 | 51 | override func didReceiveMemoryWarning() { 52 | super.didReceiveMemoryWarning() 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | @objc private func onClickButton(_ sender: UIButton) { 57 | if !flag { // display myView if flag is false. 58 | // display displayView. 59 | displayView.isHidden = false 60 | 61 | // Change button title. 62 | displayButton.setTitle("Disappear", for: .normal) 63 | 64 | flag = true 65 | } else { // hide displayView if flag is true. 66 | // hide displayView. 67 | displayView.isHidden = true 68 | 69 | // Change button title. 70 | displayButton.setTitle("Appear", for: .normal) 71 | 72 | flag = false 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/DragViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DragViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DragViewVC: BaseViewController { 12 | 13 | // Generate circleLabel 14 | lazy var circleLabel: UILabel = { 15 | let l = UILabel(frame: CGRect(x: 0, y: 0, width: 80, height: 80)) 16 | l.text = "Drag!" 17 | l.textAlignment = NSTextAlignment.center 18 | l.backgroundColor = UIColor.red 19 | l.layer.masksToBounds = true 20 | l.center = self.view.center 21 | l.layer.cornerRadius = 40.0 22 | 23 | return l 24 | }() 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | // Do any additional setup after loading the view. 30 | 31 | self.view.backgroundColor = .black 32 | 33 | // Add circleLabel on view 34 | self.view.addSubview(circleLabel) 35 | } 36 | 37 | override func didReceiveMemoryWarning() { 38 | super.didReceiveMemoryWarning() 39 | // Dispose of any resources that can be recreated. 40 | } 41 | 42 | // A method called when touch is sensed. 43 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 44 | print("touchesBegan") 45 | // Label animation. 46 | UIView.animate(withDuration: 0.06, 47 | // Processing during animation. 48 | animations: { () -> Void in 49 | // Create an affine matrix for reduction. 50 | self.circleLabel.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) 51 | }) 52 | { (Bool) -> Void in 53 | } 54 | } 55 | 56 | // A method called when sensing a drug. 57 | // (Called many times during drug) 58 | override func touchesMoved(_ touches: Set, with event: UIEvent?) { 59 | print("touchesMoved") 60 | // Get a touch event. 61 | let aTouch: UITouch = touches.first! 62 | 63 | // Get coordinates of the destination you moved. 64 | let location = aTouch.location(in: self.view) 65 | 66 | // Get coordinates before moving. 67 | let prevLocation = aTouch.previousLocation(in: self.view) 68 | 69 | // Generate CGRect. 70 | var myFrame: CGRect = self.view.frame 71 | 72 | // Take x, y distance moved by dragging. 73 | let deltaX: CGFloat = location.x - prevLocation.x 74 | let deltaY: CGFloat = location.y - prevLocation.y 75 | 76 | // Place the distance of the moved part on the coordinate of myFrame. 77 | myFrame.origin.x += deltaX 78 | myFrame.origin.y += deltaY 79 | 80 | // Added myFrame to frame. 81 | self.view.frame = myFrame 82 | } 83 | 84 | // A method called when sensing that a finger has left. 85 | override func touchesEnded(_ touches: Set, with event: UIEvent?) { 86 | print("touchesEnded") 87 | 88 | // Label animation. 89 | UIView.animate(withDuration: 0.1, 90 | // Processing during animation. 91 | animations: { () -> Void in 92 | // Create an affine matrix for magnification. 93 | self.circleLabel.transform = CGAffineTransform(scaleX: 0.4, y: 0.4) 94 | // Create an affine matrix for reduction. 95 | self.circleLabel.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) 96 | }) 97 | { (Bool) -> Void in 98 | 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/EffectProcessVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EffectProcessVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class EffectProcessVC: BaseViewController, UIWebViewDelegate { 12 | 13 | lazy var webview: UIWebView = { 14 | // Open the WebView. 15 | let wv = UIWebView() 16 | wv.delegate = self 17 | wv.frame = self.view.bounds 18 | 19 | return wv 20 | }() 21 | 22 | override func viewDidLoad() { 23 | super.viewDidLoad() 24 | 25 | // Do any additional setup after loading the view. 26 | 27 | // Add webview on view 28 | self.view.addSubview(webview) 29 | 30 | let url: URL! = URL(string: "https://medium.com/@calmone") 31 | let request: URLRequest = URLRequest(url: url) 32 | 33 | // Load started. 34 | webview.loadRequest(request) 35 | } 36 | 37 | override func didReceiveMemoryWarning() { 38 | super.didReceiveMemoryWarning() 39 | // Dispose of any resources that can be recreated. 40 | } 41 | 42 | // It will be called when all the Webs have finished loading. 43 | func webViewDidFinishLoad(_ webView: UIWebView) { 44 | print("webViewDidFinishLoad") 45 | } 46 | 47 | // It will be called when the Web starts to load. 48 | func webViewDidStartLoad(_ webView: UIWebView) { 49 | print("webViewDidStartLoad") 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ExtendingButtonTableViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExtendingButtonTableViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ExtendingButtonTableViewVC: BaseViewController { 12 | 13 | var items: [String] = ["TEST1", "TEST2", "TEST3"] 14 | var tableView: UITableView! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | // Do any additional setup after loading the view. 20 | 21 | // Get the height of the Status Bar. 22 | let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height 23 | 24 | // Get the height and width of the view. 25 | let displayWidth: CGFloat = self.view.frame.width 26 | let displayHeight: CGFloat = self.view.frame.height 27 | 28 | // Generate TableView (displayed by the height of status bar). 29 | tableView = UITableView(frame: CGRect(x: 0, y: barHeight + 50, width: displayWidth, height: displayHeight - barHeight - 50)) 30 | 31 | // Cell registration. 32 | tableView.register(UITableViewCell.self, forCellReuseIdentifier: "ExtendingCell") 33 | 34 | // Set the DataSource. 35 | tableView.dataSource = self 36 | 37 | // Set the delegate. 38 | tableView.delegate = self 39 | 40 | // Add to View. 41 | self.view.addSubview(tableView) 42 | } 43 | 44 | override func didReceiveMemoryWarning() { 45 | super.didReceiveMemoryWarning() 46 | // Dispose of any resources that can be recreated. 47 | } 48 | 49 | } 50 | 51 | extension ExtendingButtonTableViewVC: UITableViewDelegate, UITableViewDataSource { 52 | 53 | // Called when Cell is selected. 54 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 55 | print("Num: \(indexPath.row)") 56 | print("Value: \(items[indexPath.row])") 57 | } 58 | 59 | // Returns the total number of cells. 60 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 61 | print("numberOfRowsInSection") 62 | return items.count 63 | } 64 | 65 | // Editable state. 66 | func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 67 | print("canEditRowAtIndexPath") 68 | return true 69 | } 70 | 71 | // Enable button operation for a specific row. 72 | func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 73 | print("commitEdittingStyle:\(editingStyle)") 74 | } 75 | 76 | // Set a value for Cell. 77 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 78 | print("cellForRowAtIndexPath") 79 | let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "ExtendingCell", for: indexPath) 80 | cell.textLabel?.text = "\(items[indexPath.row])" 81 | return cell 82 | } 83 | 84 | // Extend the Button. 85 | func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 86 | // Share button. 87 | let shareButton: UITableViewRowAction = UITableViewRowAction(style: .normal, title: "Share") { (action, index) -> Void in 88 | tableView.isEditing = false 89 | print("share") 90 | } 91 | shareButton.backgroundColor = UIColor.blue 92 | 93 | // Archive button. 94 | let archiveButton: UITableViewRowAction = UITableViewRowAction(style: .normal, title: "Archive") { (action, index) -> Void in 95 | tableView.isEditing = false 96 | print("archive") 97 | } 98 | archiveButton.backgroundColor = UIColor.red 99 | 100 | return [shareButton, archiveButton] 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/FontVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FontViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 31.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FontVC: BaseViewController { 12 | 13 | // Display a character string of a smaller font on the label. 14 | lazy var smallLabel: UILabel = { 15 | let label = UILabel(frame: CGRect(x: 25, y: 100, width: 350, height: 150)) 16 | label.text = "Small font" 17 | label.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize) 18 | return label 19 | }() 20 | 21 | // Display the label of the system's standard font size string. 22 | lazy var normalLabel: UILabel = { 23 | let label = UILabel(frame: CGRect(x: 25, y: 130, width: 350, height: 150)) 24 | label.text = "Normal font" 25 | label.font = UIFont.systemFont(ofSize: UIFont.systemFontSize) 26 | return label 27 | }() 28 | 29 | // Display a character string of font size for UIButton on the label. 30 | lazy var buttonLabel: UILabel = { 31 | let label = UILabel(frame: CGRect(x: 25, y: 160, width: 350, height: 150)) 32 | label.text = "UIButton font size" 33 | label.font = UIFont.systemFont(ofSize: UIFont.buttonFontSize) 34 | return label 35 | }() 36 | 37 | // Display the character string of the custom font size (20) on the label. 38 | lazy var customLabel: UILabel = { 39 | let label = UILabel(frame: CGRect(x: 25, y: 190, width: 350, height: 150)) 40 | label.text = "Font size of point 20" 41 | label.font = UIFont.systemFont(ofSize: CGFloat(20)) 42 | return label 43 | }() 44 | 45 | // Display the character string of Italic Sysrem Font on the label. 46 | lazy var italicLabel: UILabel = { 47 | let label = UILabel(frame: CGRect(x: 25, y: 220, width: 350, height: 150)) 48 | label.text = "Italic Font" 49 | label.font = UIFont.italicSystemFont(ofSize: UIFont.labelFontSize) 50 | return label 51 | }() 52 | 53 | // Display the string of Bold on the label. 54 | lazy var boldLabel: UILabel = { 55 | let label = UILabel(frame: CGRect(x: 25, y: 250, width: 350, height: 150)) 56 | label.text = "Bold Font" 57 | label.font = UIFont.boldSystemFont(ofSize: UIFont.labelFontSize) 58 | return label 59 | }() 60 | 61 | // Display the character string of Arial on the label. 62 | lazy var arialLabel: UILabel = { 63 | let label = UILabel(frame: CGRect(x: 25, y: 280, width: 350, height: 150)) 64 | label.text = "ArialHebrew" 65 | label.font = UIFont(name: "ArialHebrew", size: UIFont.labelFontSize) 66 | return label 67 | }() 68 | 69 | override func viewDidLoad() { 70 | super.viewDidLoad() 71 | 72 | // Do any additional setup after loading the view. 73 | 74 | // Add UILabels on view 75 | self.view.addSubview(self.smallLabel) 76 | self.view.addSubview(self.normalLabel) 77 | self.view.addSubview(self.buttonLabel) 78 | self.view.addSubview(self.customLabel) 79 | self.view.addSubview(self.italicLabel) 80 | self.view.addSubview(self.boldLabel) 81 | self.view.addSubview(self.arialLabel) 82 | } 83 | 84 | override func didReceiveMemoryWarning() { 85 | super.didReceiveMemoryWarning() 86 | // Dispose of any resources that can be recreated. 87 | } 88 | 89 | 90 | /* 91 | // MARK: - Navigation 92 | 93 | // In a storyboard-based application, you will often want to do a little preparation before navigation 94 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 95 | // Get the new view controller using segue.destinationViewController. 96 | // Pass the selected object to the new view controller. 97 | } 98 | */ 99 | 100 | } 101 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/GravityViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GravityViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GravityViewVC: BaseViewController { 12 | 13 | // Generate label 14 | lazy var label: UILabel = { 15 | let l: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40)) 16 | l.backgroundColor = UIColor.orange 17 | l.layer.masksToBounds = true 18 | l.layer.cornerRadius = 20.0 19 | l.text = "Hello calmone!!" 20 | l.textColor = UIColor.white 21 | l.shadowColor = UIColor.gray 22 | l.textAlignment = NSTextAlignment.center 23 | l.layer.position = CGPoint(x: self.view.bounds.width/2, y: -200) 24 | 25 | return l 26 | }() 27 | 28 | // Generate boxView 29 | lazy var boxView: UIView = { 30 | let v = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 40)) 31 | v.backgroundColor = UIColor.blue 32 | v.layer.masksToBounds = true 33 | v.layer.position = CGPoint(x: self.view.frame.midX - 50, y: self.view.frame.midY) 34 | 35 | return v 36 | }() 37 | 38 | // Generate button 39 | lazy var button: UIButton = { 40 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 41 | b.layer.position = CGPoint(x: self.view.frame.midX, y: 500) 42 | b.layer.masksToBounds = true 43 | b.layer.cornerRadius = 20.0 44 | b.setTitleColor(UIColor.white, for: UIControlState.normal) 45 | b.setTitleColor(UIColor.black, for: UIControlState.highlighted) 46 | b.backgroundColor = UIColor.red 47 | b.setTitle("Dropped!", for: UIControlState.normal) 48 | b.addTarget(self, action: #selector(onClickButton(_:)), for: UIControlEvents.touchUpInside) 49 | b.tag = 0 50 | 51 | return b 52 | }() 53 | 54 | // Generate resetButton 55 | lazy var resetButton: UIButton = { 56 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 57 | b.layer.position = CGPoint(x: self.view.frame.midX, y: 400) 58 | b.layer.masksToBounds = true 59 | b.layer.cornerRadius = 20.0 60 | b.setTitleColor(UIColor.white, for: UIControlState.normal) 61 | b.setTitleColor(UIColor.black, for: UIControlState.highlighted) 62 | b.backgroundColor = UIColor.blue 63 | b.setTitle("Reset!", for: UIControlState.normal) 64 | b.addTarget(self, action: #selector(onClickButton(_:)), for: UIControlEvents.touchUpInside) 65 | b.tag = 1 66 | 67 | return b 68 | }() 69 | 70 | // The UIDynamicAnimator does not execute the animation unless you save the instance. 71 | var animator : UIDynamicAnimator! 72 | var gravity : UIGravityBehavior! 73 | 74 | override func viewDidLoad() { 75 | super.viewDidLoad() 76 | 77 | // Do any additional setup after loading the view. 78 | 79 | // Add label on view 80 | self.view.addSubview(label) 81 | 82 | // Add boxView on view 83 | self.view.addSubview(boxView) 84 | 85 | // Add button on view 86 | self.view.addSubview(button) 87 | 88 | // Add resetButton on view 89 | self.view.addSubview(resetButton) 90 | 91 | // Generate UIDynamiAnimator and save instance. 92 | animator = UIDynamicAnimator(referenceView: self.view) 93 | 94 | // Create gravity and apply it to View. 95 | gravity = UIGravityBehavior(items: [label]) 96 | 97 | // Create Collision and apply it to View. 98 | let collision = UICollisionBehavior(items: [label, boxView]) 99 | 100 | // Specify the behavior of Collision. 101 | collision.addBoundary(withIdentifier: "barrier" as NSCopying, for: UIBezierPath(rect: boxView.frame)) 102 | 103 | // Run Collision's animation. 104 | animator.addBehavior(collision) 105 | } 106 | 107 | override func didReceiveMemoryWarning() { 108 | super.didReceiveMemoryWarning() 109 | // Dispose of any resources that can be recreated. 110 | } 111 | 112 | @objc private func onClickButton(_ sender: UIButton) { 113 | switch(sender.tag) { 114 | case 0: // DropButton. 115 | // Run animation of Gravity. 116 | animator.addBehavior(gravity) 117 | case 1: // ResetButton. 118 | self.navigationController?.popViewController(animated: true) 119 | default: print("error!") 120 | } 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ImagePickerVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImagePickerVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 17.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ImagePickerVC: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 12 | 13 | var selectedImageView: UIImageView! 14 | var imagePicker: UIImagePickerController! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | // Do any additional setup after loading the view. 20 | 21 | if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) { 22 | // Instantiation 23 | imagePicker = UIImagePickerController() 24 | 25 | // Delegate setting 26 | imagePicker.delegate = self 27 | 28 | // Image acquisition destination is Photo Library 29 | imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary 30 | 31 | // Disable editing after image acquisition 32 | imagePicker.allowsEditing = false 33 | 34 | self.present(imagePicker, animated: true, completion: nil) 35 | } 36 | 37 | selectedImageView = UIImageView(frame: self.view.bounds) 38 | selectedImageView.contentMode = UIViewContentMode.scaleAspectFit 39 | self.view.addSubview(selectedImageView) 40 | } 41 | 42 | override func didReceiveMemoryWarning() { 43 | super.didReceiveMemoryWarning() 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | // It is called when an image is selected. 48 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 49 | // Acquire the selected image. 50 | if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage { 51 | selectedImageView.image = pickedImage 52 | } 53 | self.dismiss(animated: true, completion: nil) 54 | } 55 | 56 | // It is called when image selection is canceled. 57 | func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 58 | // Close the modal view 59 | self.dismiss(animated: true, completion: nil) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ImageViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ImageViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 31.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ImageViewVC: BaseViewController { 12 | 13 | lazy var imageView: UIImageView = { 14 | // Set the size of UIImageView. 15 | let width: CGFloat = self.view.bounds.width/2 16 | let height: CGFloat = 150 17 | 18 | // Set x, y of UIImageView. 19 | let posX: CGFloat = (self.view.bounds.width - width)/2 20 | let posY: CGFloat = (self.view.bounds.height - height)/2 21 | 22 | // Create UIImageView. 23 | let imageView = UIImageView(frame: CGRect(x: posX, y: posY, width: width, height: height)) 24 | 25 | // Create UIImage. 26 | let myImage: UIImage = UIImage(named: "apple.png")! 27 | 28 | // Set the image to UIImageView. 29 | imageView.image = myImage 30 | 31 | return imageView 32 | }() 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | 37 | // Do any additional setup after loading the view. 38 | 39 | // Add UIImageView to view 40 | self.view.addSubview(self.imageView) 41 | } 42 | 43 | override func didReceiveMemoryWarning() { 44 | super.didReceiveMemoryWarning() 45 | // Dispose of any resources that can be recreated. 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/LabelVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LabelVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class LabelVC: BaseViewController { 12 | 13 | lazy var label: UILabel = { 14 | // Define the size of the label. 15 | let width: CGFloat = 300 16 | let height: CGFloat = 100 17 | 18 | // Define coordinates to be placed. 19 | // (center of screen) 20 | let posX: CGFloat = self.view.bounds.width/2 - width/2 21 | let posY: CGFloat = self.view.bounds.height/2 - height/2 22 | 23 | // Label Create. 24 | let label: UILabel = UILabel(frame: CGRect(x: posX, y: posY, width: width, height: height)) 25 | 26 | // Define background color. 27 | label.backgroundColor = .orange 28 | 29 | // Define text color. 30 | label.textColor = .white 31 | 32 | // Define text font. 33 | label.font = .systemFont(ofSize: 20, weight: .regular) 34 | 35 | // Define text of label. 36 | label.text = "Hello Calmone!! :)" 37 | 38 | // Define count of line. 39 | // '0' is infinity 40 | label.numberOfLines = 0 41 | 42 | // Round UILabel frame. 43 | label.layer.masksToBounds = true 44 | 45 | // Radius of rounded corner. 46 | label.layer.cornerRadius = 20.0 47 | 48 | // Define shadow color. 49 | label.shadowColor = .gray 50 | 51 | // Define text Alignment. 52 | // options) .left, .right, .center, .justified, .natural 53 | label.textAlignment = .center 54 | 55 | return label 56 | }() 57 | 58 | override func viewDidLoad() { 59 | super.viewDidLoad() 60 | 61 | // Do any additional setup after loading the view. 62 | 63 | // Add UILabel to view. 64 | self.view.addSubview(self.label) 65 | } 66 | 67 | override func didReceiveMemoryWarning() { 68 | super.didReceiveMemoryWarning() 69 | // Dispose of any resources that can be recreated. 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/LimitedTextFieldVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LimitedTextFieldVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class LimitedTextFieldVC: BaseViewController, UITextFieldDelegate { 12 | 13 | // Generate UITextField. 14 | lazy var limitdTextField: UITextField = { 15 | let tf: UITextField = UITextField(frame: CGRect(x :0, y: 0, width: 200, height: 30)) 16 | // First character to display. 17 | tf.text = "Hi calmone :)" 18 | 19 | // Set Delegate. 20 | tf.delegate = self 21 | 22 | // Display frame line. 23 | tf.borderStyle = UITextBorderStyle.roundedRect 24 | 25 | // The position to display in UITextField. 26 | tf.layer.position = CGPoint(x: self.view.bounds.width/2, y: 150) 27 | 28 | return tf 29 | }() 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | 34 | // Do any additional setup after loading the view. 35 | 36 | // Add limitedTextField on view 37 | self.view.addSubview(limitdTextField) 38 | } 39 | 40 | override func didReceiveMemoryWarning() { 41 | super.didReceiveMemoryWarning() 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | // Called when text is edited. 46 | func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 47 | // Decide the maximum number of characters. 48 | let maxLength: Int = 20 49 | 50 | // Acquires the input character and the input character together. 51 | let str = (textField.text ?? "") + string 52 | 53 | // Return true if the number of characters is maxLength or less. 54 | if str.count < maxLength { 55 | return true 56 | } else { 57 | appDelegate()?.showAlert(vc: self, title: "characters", message: "It exceeds 20 characters", actionTitle: "OK", actionStyle: .default) 58 | return false 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/MenuItemVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MenuItemVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MenuItemVC: BaseViewController, UITextFieldDelegate { 12 | 13 | lazy var textField: UITextField = { 14 | // Create TextField. 15 | let tf: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) 16 | tf.text = "Hello Swift!" 17 | tf.delegate = self 18 | tf.borderStyle = UITextBorderStyle.roundedRect 19 | tf.layer.position = CGPoint(x: self.view.frame.width/2, y: 200) 20 | 21 | return tf 22 | }() 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | 27 | // Do any additional setup after loading the view. 28 | 29 | // Add TextField on view 30 | self.view.addSubview(self.textField) 31 | 32 | // MenuController generated. 33 | let menuController: UIMenuController = UIMenuController.shared 34 | 35 | // Show MenuController. 36 | menuController.isMenuVisible = true 37 | 38 | // Set the direction of the arrow down. 39 | menuController.arrowDirection = UIMenuControllerArrowDirection.down 40 | 41 | // Set rect, view. 42 | menuController.setTargetRect(CGRect.zero, in: self.view) 43 | 44 | // MenuItem generation. 45 | let menuItem_1: UIMenuItem = UIMenuItem(title: "Menu1", action: #selector(onMenu1(sender:))) 46 | let menuItem_2: UIMenuItem = UIMenuItem(title: "Menu2", action: #selector(onMenu2(sender:))) 47 | let menuItem_3: UIMenuItem = UIMenuItem(title: "Menu3", action: #selector(onMenu3(sender:))) 48 | 49 | // Store MenuItem in array. 50 | let myMenuItems: [UIMenuItem] = [menuItem_1, menuItem_2, menuItem_3] 51 | 52 | // Added MenuItem to MenuController. 53 | menuController.menuItems = myMenuItems 54 | } 55 | 56 | override func didReceiveMemoryWarning() { 57 | super.didReceiveMemoryWarning() 58 | // Dispose of any resources that can be recreated. 59 | } 60 | 61 | // Called immediately after UITextField is started editing. 62 | func textFieldDidBeginEditing(_ textField: UITextField) { 63 | print("textFieldDidBeginEditing:" + textField.text!) 64 | } 65 | 66 | // Called just before UITextField finished editing. 67 | func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { 68 | print("textFieldShouldEndEditing:" + textField.text!) 69 | return true 70 | } 71 | 72 | // Make the created MenuItem visible. 73 | override func canPerformAction(_ action: Selector, withSender sender: Any!) -> Bool { 74 | if [#selector(onMenu1(sender:)), #selector(onMenu2(sender:)), #selector(onMenu3(sender:))].contains(action) { 75 | return true 76 | } else { 77 | return false 78 | } 79 | } 80 | 81 | // Called when the created MenuItem is pressed. 82 | @objc internal func onMenu1(sender: UIMenuItem) { 83 | print("onMenu1") 84 | } 85 | 86 | @objc internal func onMenu2(sender: UIMenuItem) { 87 | print("onMenu2") 88 | } 89 | 90 | @objc internal func onMenu3(sender: UIMenuItem) { 91 | print("onMenu3") 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/MotionEffectVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MotionEffectVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MotionEffectVC: BaseViewController { 12 | 13 | lazy var boxView: UIView = { 14 | // Create UIView. 15 | let v = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) 16 | v.backgroundColor = UIColor.black 17 | v.layer.masksToBounds = true 18 | v.layer.cornerRadius = 20.0 19 | v.layer.position = self.view.center 20 | v.layer.zPosition = 1 21 | 22 | return v 23 | }() 24 | 25 | lazy var label: UILabel = { 26 | // Create Label. 27 | let l = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) 28 | l.backgroundColor = UIColor.gray 29 | l.layer.masksToBounds = true 30 | l.layer.cornerRadius = 20.0 31 | l.text = "Hello Calmone!!" 32 | l.textColor = UIColor.white 33 | l.shadowColor = UIColor.gray 34 | l.textAlignment = NSTextAlignment.center 35 | l.layer.position = self.view.center 36 | l.layer.zPosition = 2 37 | 38 | return l 39 | }() 40 | 41 | var group1: UIMotionEffectGroup! 42 | var group2: UIMotionEffectGroup! 43 | 44 | override func viewDidLoad() { 45 | super.viewDidLoad() 46 | 47 | // Do any additional setup after loading the view. 48 | 49 | // Add boxView on view 50 | self.view.addSubview(self.boxView) 51 | 52 | // Add label on view 53 | self.view.addSubview(self.label) 54 | 55 | applyMotionEffect(toView: self.boxView, magnitude: 50) 56 | applyMotionEffect(toView: self.label, magnitude: -100) 57 | } 58 | 59 | private func applyMotionEffect(toView view: UIView, magnitude: Float) { 60 | // Create an effect that changes the position of view according to the tilt of the terminal in the x axis direction. 61 | let xMotion = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis) 62 | xMotion.minimumRelativeValue = -magnitude 63 | xMotion.maximumRelativeValue = magnitude 64 | 65 | // Create an effect that changes the position of view according to the tilt of the terminal in the y axis direction. 66 | let yMotion = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis) 67 | yMotion.minimumRelativeValue = -magnitude 68 | yMotion.maximumRelativeValue = -magnitude 69 | 70 | // Create a group of motion effects. 71 | let group = UIMotionEffectGroup() 72 | group.motionEffects = [xMotion, yMotion] 73 | 74 | // Apply the effect to view. 75 | view.addMotionEffect(group) 76 | } 77 | 78 | override func didReceiveMemoryWarning() { 79 | super.didReceiveMemoryWarning() 80 | // Dispose of any resources that can be recreated. 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/PageControlVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PageControlVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 7.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PageControlVC: BaseViewController, UIScrollViewDelegate { 12 | 13 | // Define the number of pages. 14 | let pageSize = 4 15 | 16 | lazy var pageControl: UIPageControl = { 17 | // Create a UIPageControl. 18 | let pageControl = UIPageControl(frame: CGRect(x: 0, y: self.view.frame.maxY - 100, width: self.view.frame.maxX, height:50)) 19 | pageControl.backgroundColor = UIColor.orange 20 | 21 | // Set the number of pages to page control. 22 | pageControl.numberOfPages = pageSize 23 | 24 | // Set the current page. 25 | pageControl.currentPage = 0 26 | pageControl.isUserInteractionEnabled = false 27 | 28 | return pageControl 29 | }() 30 | 31 | lazy var scrollView: UIScrollView = { 32 | // Create a UIScrollView. 33 | let scrollView = UIScrollView(frame: self.view.frame) 34 | 35 | // Hide the vertical and horizontal indicators. 36 | scrollView.showsHorizontalScrollIndicator = false; 37 | scrollView.showsVerticalScrollIndicator = false 38 | 39 | // Allow paging. 40 | scrollView.isPagingEnabled = true 41 | 42 | // Set delegate of ScrollView. 43 | scrollView.delegate = self 44 | 45 | // Specify the screen size of the scroll. 46 | scrollView.contentSize = CGSize(width: CGFloat(pageSize) * self.view.frame.maxX, height: 0) 47 | 48 | return scrollView 49 | }() 50 | 51 | override func viewDidLoad() { 52 | super.viewDidLoad() 53 | 54 | // Do any additional setup after loading the view. 55 | 56 | // Set the background color to Cyan. 57 | self.view.backgroundColor = .green 58 | 59 | // Get the vertical and horizontal sizes of the view. 60 | let width = self.view.frame.maxX, height = self.view.frame.maxY 61 | 62 | // Generate buttons for the number of pages. 63 | for i in 0 ..< pageSize { 64 | // Generate different labels for each page. 65 | let label: UILabel = UILabel(frame: CGRect(x: CGFloat(i) * width + width/2 - 40, y: height/2 - 40, width: 80, height: 80)) 66 | label.backgroundColor = .red 67 | label.textColor = .white 68 | label.textAlignment = .center 69 | label.layer.masksToBounds = true 70 | label.text = "Page\(i)" 71 | 72 | label.font = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize) 73 | label.layer.cornerRadius = 40.0 74 | 75 | scrollView.addSubview(label) 76 | } 77 | 78 | // Add UIScrollView, UIPageControl on view 79 | self.view.addSubview(self.scrollView) 80 | self.view.addSubview(self.pageControl) 81 | } 82 | 83 | override func didReceiveMemoryWarning() { 84 | super.didReceiveMemoryWarning() 85 | // Dispose of any resources that can be recreated. 86 | } 87 | 88 | func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 89 | // When the number of scrolls is one page worth. 90 | if fmod(scrollView.contentOffset.x, scrollView.frame.maxX) == 0 { 91 | // Switch the location of the page. 92 | pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.maxX) 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/PasswordAlertVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PasswordAlertVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 13.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PasswordAlertVC: BaseViewController, UITextFieldDelegate { 12 | 13 | // Generate button. 14 | lazy var button: UIButton = { 15 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 40)) 16 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: 200) 17 | b.layer.cornerRadius = 20.0 18 | b.backgroundColor = UIColor.red 19 | b.setTitle("Invoke UIAlert", for: .normal) 20 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 21 | 22 | return b 23 | }() 24 | 25 | override func viewDidLoad() { 26 | super.viewDidLoad() 27 | 28 | // Do any additional setup after loading the view. 29 | 30 | // Add button on view 31 | self.view.addSubview(button) 32 | } 33 | 34 | override func didReceiveMemoryWarning() { 35 | super.didReceiveMemoryWarning() 36 | // Dispose of any resources that can be recreated. 37 | } 38 | 39 | @objc private func onClickButton(sender: UIButton) { 40 | // Alert generation. 41 | let alert: UIAlertController = UIAlertController(title: "title", message: "message", preferredStyle: UIAlertControllerStyle.alert) 42 | 43 | // Cancel action generation. 44 | let CancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.destructive) { (action: UIAlertAction!) -> Void in 45 | print("Cancel") 46 | } 47 | 48 | // OK action generation. 49 | let OkAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (action: UIAlertAction!) -> Void in 50 | print("OK") 51 | } 52 | 53 | // Added TextField to Alert. 54 | alert.addTextField { (textField: UITextField!) -> Void in 55 | 56 | // Hide the entered characters. 57 | textField.isSecureTextEntry = true 58 | 59 | // Set Delegate. 60 | textField.delegate = self 61 | } 62 | 63 | // Added action to Alert. 64 | alert.addAction(CancelAction) 65 | alert.addAction(OkAction) 66 | 67 | // Activate Alert. 68 | present(alert, animated: true, completion: nil) 69 | } 70 | 71 | func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 72 | // Display the entered character. 73 | print(string) 74 | return true 75 | } 76 | 77 | func textFieldDidEndEditing(_ textField: UITextField) { 78 | // Display the entered characters. 79 | print(textField.text ?? "") 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/PasswordTextFieldVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PasswordTextFieldVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PasswordTextFieldVC: BaseViewController, UITextFieldDelegate { 12 | 13 | lazy var passwordTextField: UITextField = { 14 | // Generate UITextField. 15 | let tf: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) 16 | 17 | // Set Delegate. 18 | tf.delegate = self 19 | 20 | // Display frame line. 21 | tf.borderStyle = UITextBorderStyle.roundedRect 22 | 23 | // The position to display in UITextField. 24 | tf.layer.position = CGPoint(x: self.view.bounds.width/2, y: 150) 25 | 26 | // Place the entered characters in non-display mode. 27 | tf.isSecureTextEntry = true 28 | 29 | return tf 30 | }() 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | // Do any additional setup after loading the view. 36 | 37 | // Add passwordTextField on view 38 | self.view.addSubview(passwordTextField) 39 | } 40 | 41 | override func didReceiveMemoryWarning() { 42 | super.didReceiveMemoryWarning() 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | func textFieldShouldReturn(_ textField: UITextField) -> Bool { 47 | if let text = textField.text, text.count > 0 { 48 | appDelegate()?.showAlert(vc: self, title: "password", message: text, actionTitle: "OK", actionStyle: .default) 49 | } else { 50 | print("Empty") 51 | } 52 | return true 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/PickerViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PickerViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PickerViewVC: BaseViewController, UIPickerViewDelegate, UIPickerViewDataSource { 12 | 13 | lazy var pickerView: UIPickerView = { 14 | // Generate UIPickerView. 15 | let picker = UIPickerView() 16 | 17 | // Specify the size. 18 | picker.frame = CGRect(x: 0, y: 150, width: self.view.bounds.width, height: 180.0) 19 | 20 | // Set the background Color. 21 | picker.backgroundColor = .white 22 | 23 | // Set the delegate. 24 | picker.delegate = self 25 | 26 | // Set the dataSource. 27 | picker.dataSource = self 28 | 29 | return picker 30 | }() 31 | 32 | private let values: [String] = ["A","B","C","D","E","F","G","H","I"] 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | 37 | // Do any additional setup after loading the view. 38 | 39 | // Add UIPickerView on view 40 | self.view.addSubview(self.pickerView) 41 | } 42 | 43 | override func didReceiveMemoryWarning() { 44 | super.didReceiveMemoryWarning() 45 | // Dispose of any resources that can be recreated. 46 | } 47 | 48 | func numberOfComponents(in pickerView: UIPickerView) -> Int { 49 | return 1 50 | } 51 | 52 | // Data source method that returns the number of rows to display in the picker. 53 | // (Implementation required) 54 | func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 55 | return values.count 56 | } 57 | 58 | // Delegate method that returns the value to be displayed in the picker. 59 | func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 60 | return values[row] 61 | } 62 | 63 | // A method called when the picker is selected. 64 | func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 65 | print("row: \(row)") 66 | print("value: \(values[row])") 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/PopoverVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PopoverVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 20.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PopoverVC: BaseViewController { 12 | 13 | // Generate Button 14 | lazy var button: UIButton = { 15 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 16 | b.layer.position = self.view.center 17 | b.layer.masksToBounds = true 18 | b.layer.cornerRadius = 20.0 19 | b.backgroundColor = UIColor.orange 20 | b.setTitle("Present!", for: UIControlState.normal) 21 | b.addTarget(self, action: #selector(onButtonClick(_:)), for: UIControlEvents.touchUpInside) 22 | 23 | return b 24 | }() 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | // Do any additional setup after loading the view. 30 | 31 | // Add button on view 32 | self.view.addSubview(button) 33 | } 34 | 35 | override func didReceiveMemoryWarning() { 36 | super.didReceiveMemoryWarning() 37 | // Dispose of any resources that can be recreated. 38 | } 39 | 40 | @objc private func onButtonClick(_ sender: UIButton) { 41 | // Generate ViewController for content. 42 | let popover = UIViewController() 43 | 44 | // Specify the size of the content ViewController. 45 | popover.preferredContentSize = CGSize(width: 200, height: 200) 46 | 47 | // Set the background of the content ViewController to blue. 48 | popover.view.backgroundColor = UIColor.blue 49 | popover.modalPresentationStyle = .popover 50 | 51 | if let presentationController = popover.popoverPresentationController { 52 | presentationController.permittedArrowDirections = .any 53 | presentationController.sourceView = sender 54 | presentationController.sourceRect = sender.bounds 55 | } 56 | 57 | present(popover, animated: true, completion: nil) 58 | 59 | DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { 60 | popover.dismiss(animated: true, completion: nil) 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ProgressVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProgressVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ProgressVC: BaseViewController { 12 | 13 | lazy var progressView: UIProgressView = { 14 | // Create a ProgressView. 15 | let pv: UIProgressView = UIProgressView(frame: CGRect(x:0, y:0, width:200, height:10)) 16 | pv.progressTintColor = UIColor.green 17 | pv.trackTintColor = UIColor.white 18 | 19 | // Set the coordinates. 20 | pv.layer.position = CGPoint(x: self.view.frame.width/2, y: 200) 21 | 22 | // Set the height of the bar (1.0 times horizontally, 2.0 times vertically). 23 | pv.transform = CGAffineTransform(scaleX: 1.0, y: 2.0) 24 | 25 | // Set the progress degree (0.0 to 1.0). 26 | pv.progress = 0.0 27 | 28 | // Add an animation. 29 | pv.setProgress(1.0, animated: true) 30 | 31 | return pv 32 | }() 33 | 34 | override func viewDidLoad() { 35 | super.viewDidLoad() 36 | 37 | // Do any additional setup after loading the view. 38 | 39 | self.view.backgroundColor = .black 40 | 41 | // Add UIProgressView on view 42 | self.view.addSubview(self.progressView) 43 | } 44 | 45 | override func didReceiveMemoryWarning() { 46 | super.didReceiveMemoryWarning() 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ResizeImageVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ResizeImageVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 17.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ResizeImageVC: BaseViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Prepare the UIImage to be resized. 19 | let image = UIImage(named: "vertical.jpeg")! 20 | 21 | // Prepare UIImage after resizing. 22 | let resize = image.ResizeUIImage(width: self.view.frame.midX, height: self.view.frame.midY) 23 | 24 | // Set the UIImage after resizing to UIImageView. 25 | let imageView = UIImageView(image: resize) 26 | 27 | imageView.layer.position = CGPoint(x: self.view.frame.midX, y: self.view.frame.midY) 28 | 29 | self.view.addSubview(imageView) 30 | } 31 | 32 | override func didReceiveMemoryWarning() { 33 | super.didReceiveMemoryWarning() 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | } 38 | 39 | fileprivate extension UIImage { 40 | 41 | // Create a class method of Resize. 42 | func ResizeUIImage(width: CGFloat, height: CGFloat) -> UIImage! { 43 | 44 | // Prepare the context of the specified image size. 45 | UIGraphicsBeginImageContext(CGSize(width: width, height: height)) 46 | 47 | // Draw the image in the context. 48 | self.draw(in: CGRect(x: 0, y: 0, width: width, height: height)) 49 | 50 | // Create a UIImage from the context. 51 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 52 | 53 | // Close the context. 54 | UIGraphicsEndImageContext() 55 | 56 | return newImage 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ScreenshotVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScreenshotVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 20.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ScreenshotVC: BaseViewController { 12 | 13 | // Generate Label. 14 | lazy var label: UILabel = { 15 | let l = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) 16 | l.text = "Circle" 17 | l.textColor = UIColor.white 18 | l.layer.cornerRadius = 50.0 19 | l.layer.masksToBounds = true 20 | l.backgroundColor = UIColor.orange 21 | l.textAlignment = NSTextAlignment.center 22 | l.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2 - 100) 23 | 24 | return l 25 | }() 26 | 27 | // Generate ImageView. 28 | lazy var imageView: UIImageView = { 29 | let iv = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) 30 | iv.layer.borderColor = UIColor.black.cgColor 31 | iv.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height - 200) 32 | iv.layer.borderWidth = 0.5 33 | 34 | return iv 35 | }() 36 | 37 | // Generate Button 38 | lazy var button: UIButton = { 39 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 20)) 40 | b.setTitle("push", for: UIControlState.normal) 41 | b.setTitleColor(UIColor.blue, for: UIControlState.normal) 42 | b.addTarget(self, action: #selector(onClickButton(_:)), for: UIControlEvents.touchDown) 43 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height - 50) 44 | 45 | return b 46 | }() 47 | 48 | override func viewDidLoad() { 49 | super.viewDidLoad() 50 | 51 | // Do any additional setup after loading the view. 52 | 53 | // Add label on view 54 | self.view.addSubview(label) 55 | 56 | // Add imageView on view 57 | self.view.addSubview(imageView) 58 | 59 | // Add button on view 60 | self.view.addSubview(button) 61 | } 62 | 63 | override func didReceiveMemoryWarning() { 64 | super.didReceiveMemoryWarning() 65 | // Dispose of any resources that can be recreated. 66 | } 67 | 68 | @objc private func onClickButton(_ sender: UIButton) { 69 | // Acquire capture image. 70 | let myImage = label.GetImage() 71 | 72 | // Set to ImageView image. 73 | imageView.image = myImage 74 | 75 | // Adjust the image to the size of the UIImageView while keeping the aspect ratio. 76 | imageView.contentMode = UIViewContentMode.scaleAspectFit 77 | } 78 | 79 | } 80 | 81 | fileprivate extension UIView { 82 | 83 | func GetImage() -> UIImage{ 84 | 85 | // Get range to capture. 86 | let rect = self.bounds 87 | 88 | // Create the context of the bitmap image. 89 | UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0) 90 | let context: CGContext = UIGraphicsGetCurrentContext()! 91 | 92 | // Copy the drawing in the target view to the context. 93 | self.layer.render(in: context) 94 | 95 | // Get the current context's bitmap as UIImage. 96 | let capturedImage : UIImage = UIGraphicsGetImageFromCurrentImageContext()! 97 | 98 | // Close the context. 99 | UIGraphicsEndImageContext() 100 | 101 | return capturedImage 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ScrollViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScrollViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 6.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ScrollViewVC: BaseViewController { 12 | 13 | lazy var scrollView: UIScrollView = { 14 | let scrollView: UIScrollView = UIScrollView() 15 | 16 | // Generate ScrollView. 17 | scrollView.frame = self.view.frame 18 | 19 | // Disable ScrollView bounces 20 | scrollView.bounces = false 21 | 22 | // Set the image in UIImage. 23 | let image = UIImage(named: "vertical.jpeg")! 24 | 25 | // Create a UIImageView. 26 | let imageView = UIImageView() 27 | 28 | // Set myImage to the image of imageView. 29 | imageView.image = image 30 | 31 | // Set the value of frame size 32 | imageView.frame.size = image.size 33 | 34 | // Set the aspect ratio of the image. 35 | imageView.contentMode = UIViewContentMode.scaleAspectFill 36 | 37 | // Add imageView to ScrollView. 38 | scrollView.addSubview(imageView) 39 | 40 | // Set contentSize to ScrollView. 41 | scrollView.contentSize = imageView.frame.size 42 | 43 | return scrollView 44 | }() 45 | 46 | override func viewDidLoad() { 47 | super.viewDidLoad() 48 | 49 | // Do any additional setup after loading the view. 50 | 51 | // Add UIScrollView on view 52 | self.view.addSubview(self.scrollView) 53 | } 54 | 55 | override func didReceiveMemoryWarning() { 56 | super.didReceiveMemoryWarning() 57 | // Dispose of any resources that can be recreated. 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SearchBarVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SearchBarVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SearchBarVC: BaseViewController, UISearchBarDelegate { 12 | 13 | lazy var searchBar: UISearchBar = { 14 | // Create a search bar. 15 | let searchBar = UISearchBar() 16 | searchBar.delegate = self 17 | searchBar.frame = CGRect(x: 0, y: 0, width: 300, height: 100) 18 | searchBar.layer.position = CGPoint(x: self.view.bounds.width/2, y: 150) 19 | 20 | // Add a shadow. 21 | searchBar.layer.shadowColor = UIColor.black.cgColor 22 | searchBar.layer.shadowOpacity = 0.5 23 | searchBar.layer.masksToBounds = false 24 | 25 | // Enable the Cancel button. 26 | searchBar.showsCancelButton = true 27 | 28 | // Disable the bookmark button. 29 | searchBar.showsBookmarkButton = false 30 | 31 | // Set bar style to Default. 32 | searchBar.searchBarStyle = UISearchBarStyle.default 33 | 34 | // Set a title. 35 | searchBar.prompt = "Title" 36 | 37 | // Set descriptive text. 38 | searchBar.placeholder = "Please enter here" 39 | 40 | // Set the color of the cursor and cancel button. 41 | searchBar.tintColor = UIColor.red 42 | 43 | // The search result display button is not displayed. 44 | searchBar.showsSearchResultsButton = false 45 | 46 | return searchBar 47 | }() 48 | 49 | lazy var label : UILabel = { 50 | // Create a UILabel. 51 | let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) 52 | label.center = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 53 | label.text = "" 54 | label.layer.borderWidth = 1.0 55 | label.layer.borderColor = UIColor.gray.cgColor 56 | label.layer.cornerRadius = 10.0 57 | 58 | return label 59 | }() 60 | 61 | override func viewDidLoad() { 62 | super.viewDidLoad() 63 | 64 | // Do any additional setup after loading the view. 65 | 66 | // Add UISearchBar on view 67 | self.view.addSubview(self.searchBar) 68 | 69 | // Add UILabel on view 70 | self.view.addSubview(self.label) 71 | } 72 | 73 | override func didReceiveMemoryWarning() { 74 | super.didReceiveMemoryWarning() 75 | // Dispose of any resources that can be recreated. 76 | } 77 | 78 | // Called whenever text is changed 79 | func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { 80 | self.label.text = searchText 81 | } 82 | 83 | // Called when the Cancel button is pressed 84 | func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { 85 | self.label.text = "" 86 | self.searchBar.text = "" 87 | } 88 | 89 | // Called when the Search button is pressed 90 | func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { 91 | self.label.text = "Searching" 92 | self.searchBar.text = "" 93 | self.view.endEditing(true) 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SecondScreenVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondScreenVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondScreenVC: BaseViewController { 12 | 13 | var secondWindow: UIWindow! 14 | 15 | lazy var label: UILabel = { 16 | // Create a label. 17 | let l: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 18 | l.backgroundColor = UIColor.orange 19 | l.layer.masksToBounds = true 20 | l.layer.cornerRadius = 20.0 21 | l.text = "Hello 1st Screen" 22 | l.textColor = UIColor.white 23 | l.shadowColor = UIColor.gray 24 | l.textAlignment = NSTextAlignment.center 25 | l.layer.position = CGPoint(x: self.view.bounds.width/2, y: 200) 26 | 27 | return l 28 | }() 29 | 30 | override func viewDidLoad() { 31 | super.viewDidLoad() 32 | 33 | // Do any additional setup after loading the view. 34 | 35 | let screen: [UIScreen] = UIScreen.screens 36 | 37 | // If there are two screens being connected, the second one is displayed. 38 | if screen.count > 1 { 39 | let screen: UIScreen = UIScreen.screens[1] 40 | showSecondScreenWindow(screen: screen) 41 | } 42 | 43 | // Notification that occurs when the connection to the screen is lost. 44 | let defaultCenter: NotificationCenter = NotificationCenter.default 45 | defaultCenter.addObserver(self, selector: #selector(screenDidConnect(notification:)), name: NSNotification.Name.UIScreenDidConnect, object: nil) 46 | defaultCenter.addObserver(self, selector: #selector(screenDidDisconnect(notification:)), name: NSNotification.Name.UIScreenDidDisconnect, object: nil) 47 | defaultCenter.addObserver(self, selector: #selector(screenDidModeChange(notification:)), name: NSNotification.Name.UIScreenModeDidChange, object: nil) 48 | 49 | // Add label on view 50 | self.view.addSubview(label) 51 | } 52 | 53 | override func didReceiveMemoryWarning() { 54 | super.didReceiveMemoryWarning() 55 | // Dispose of any resources that can be recreated. 56 | } 57 | 58 | // When the screen is connected. 59 | @objc func screenDidConnect(notification: NSNotification){ 60 | print("screenDidConnect") 61 | let screen: [UIScreen] = UIScreen.screens 62 | if screen.count > 1 { 63 | let screen: UIScreen = UIScreen.screens[1] 64 | showSecondScreenWindow(screen: screen) 65 | } 66 | } 67 | 68 | // When the screen is disconnected. 69 | @objc func screenDidDisconnect(notification: NSNotification){ 70 | print("screenDidDisconnect") 71 | } 72 | 73 | // When the screen mode changes. 74 | @objc func screenDidModeChange(notification: NSNotification){ 75 | print("screenDidModeChange") 76 | } 77 | 78 | // The layout of the screen on the second screen. 79 | func showSecondScreenWindow(screen: UIScreen!){ 80 | secondWindow = UIWindow() 81 | secondWindow.screen = screen 82 | secondWindow.frame = CGRect(x:0, y:0, width:screen.bounds.width, height:screen.bounds.height) 83 | secondWindow.backgroundColor = UIColor.red 84 | self.secondWindow.makeKeyAndVisible() 85 | 86 | // Create a label. 87 | let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 88 | label.backgroundColor = UIColor.orange 89 | label.layer.masksToBounds = true 90 | label.layer.cornerRadius = 20.0 91 | label.text = "Hello Second Screen" 92 | label.textColor = UIColor.white 93 | label.shadowColor = UIColor.gray 94 | label.textAlignment = NSTextAlignment.center 95 | label.layer.position = CGPoint(x: self.secondWindow.bounds.width/2, y: 200) 96 | self.secondWindow.addSubview(label) 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SectionTableViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionTableViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 8.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SectionTableViewVC: BaseViewController, UITableViewDelegate, UITableViewDataSource { 12 | 13 | // Define the array to use in the Table. 14 | private let iOSItems: [String] = ["iOS12", "iOS11", "iOS10", "iOS9", "iOS8", "iOS7"] 15 | private let AOSItems: [String] = ["9.x", "8.x", "7.x", "6.x"] 16 | 17 | // Define the array to be used in Section. 18 | private let sections: [String] = ["iOS", "AOS"] 19 | 20 | lazy var tableView: UITableView = { 21 | // Get the height of the Status Bar. 22 | let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height 23 | 24 | // Get the height and width of the View. 25 | let displayWidth: CGFloat = self.view.frame.width 26 | let displayHeight: CGFloat = self.view.frame.height 27 | 28 | let tableView: UITableView = UITableView(frame: CGRect(x: 0, y: barHeight, width: displayWidth, height: displayHeight - barHeight)) 29 | 30 | // Register the Cell name. 31 | tableView.register(UITableViewCell.self, forCellReuseIdentifier: "sectionTableViewCell") 32 | 33 | // Set the DataSource. 34 | tableView.dataSource = self 35 | 36 | // Set Delegate. 37 | tableView.delegate = self 38 | 39 | return tableView 40 | }() 41 | 42 | override func viewDidLoad() { 43 | super.viewDidLoad() 44 | 45 | // Do any additional setup after loading the view. 46 | 47 | // Add UITableView on view 48 | self.view.addSubview(self.tableView) 49 | } 50 | 51 | override func didReceiveMemoryWarning() { 52 | super.didReceiveMemoryWarning() 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | // Returns the number of sections. 57 | func numberOfSections(in tableView: UITableView) -> Int { 58 | return sections.count 59 | } 60 | 61 | // Returns the title of the section. 62 | func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 63 | return sections[section] 64 | } 65 | 66 | // Called when Cell is selected. 67 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 68 | if indexPath.section == 0 { 69 | print("Value: \(iOSItems[indexPath.row])") 70 | } else if indexPath.section == 1 { 71 | print("Value: \(AOSItems[indexPath.row])") 72 | } else { 73 | return 74 | } 75 | } 76 | 77 | // Returns the total number of arrays to display in the table. 78 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 79 | if section == 0 { 80 | return iOSItems.count 81 | } else if section == 1 { 82 | return AOSItems.count 83 | } else { 84 | return 0 85 | } 86 | } 87 | 88 | // Set a value in Cell. 89 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 90 | 91 | let cell = tableView.dequeueReusableCell(withIdentifier: "sectionTableViewCell", for: indexPath) 92 | 93 | if indexPath.section == 0 { 94 | cell.textLabel?.text = "\(iOSItems[indexPath.row])" 95 | } else if indexPath.section == 1 { 96 | cell.textLabel?.text = "\(AOSItems[indexPath.row])" 97 | } else { 98 | return UITableViewCell() 99 | } 100 | 101 | return cell 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SegmentedControlVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SegmentedControlVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SegmentedControlVC: BaseViewController { 12 | 13 | lazy var segLabel: UILabel = { 14 | // Create Label. 15 | let l: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) 16 | l.backgroundColor = UIColor.white 17 | l.layer.masksToBounds = true 18 | l.layer.cornerRadius = 75.0 19 | l.textColor = UIColor.white 20 | l.shadowColor = UIColor.gray 21 | l.font = UIFont.systemFont(ofSize: 30.0) 22 | l.textAlignment = NSTextAlignment.center 23 | l.layer.position = CGPoint(x: self.view.bounds.width/2, y: 200) 24 | 25 | return l 26 | }() 27 | 28 | lazy var segCon: UISegmentedControl = { 29 | // Create segmentedControl. 30 | let sc: UISegmentedControl = UISegmentedControl(items: array) 31 | sc.center = CGPoint(x: self.view.frame.width/2, y: 400) 32 | sc.backgroundColor = UIColor.gray 33 | sc.tintColor = UIColor.white 34 | 35 | // Add an event. 36 | sc.addTarget(self, action: #selector(segconChanged(segcon:)), for: UIControlEvents.valueChanged) 37 | 38 | return sc 39 | }() 40 | 41 | // Create an array to display. 42 | let array: [String] = ["Red", "Blue", "Green"] 43 | 44 | override func viewDidLoad() { 45 | super.viewDidLoad() 46 | 47 | // Do any additional setup after loading the view. 48 | 49 | // Add UISegmentedControl on view 50 | self.view.addSubview(self.segCon) 51 | 52 | // Add UILabel on view 53 | self.view.addSubview(self.segLabel) 54 | } 55 | 56 | override func didReceiveMemoryWarning() { 57 | super.didReceiveMemoryWarning() 58 | // Dispose of any resources that can be recreated. 59 | } 60 | 61 | // Called when the value of SwtterminedControl has changed. 62 | @objc func segconChanged(segcon: UISegmentedControl) { 63 | var color: UIColor! 64 | var text: String! 65 | 66 | switch segcon.selectedSegmentIndex { 67 | case 0: 68 | color = UIColor.red 69 | text = "Red" 70 | case 1: 71 | color = UIColor.blue 72 | text = "Blue" 73 | case 2: 74 | color = UIColor.green 75 | text = "Green" 76 | default: return 77 | } 78 | 79 | self.segLabel.backgroundColor = color 80 | self.segLabel.text = text 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SliderVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SliderVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SliderVC: BaseViewController { 12 | 13 | // Set the image. 14 | private let inputImage = CIImage(image: UIImage(named: "vertical.jpeg")!) 15 | 16 | // Define the ImageView. 17 | lazy var imageView: UIImageView = { 18 | // Create a UIImageView. 19 | let imageView = UIImageView(frame: self.view.frame) 20 | imageView.image = UIImage(ciImage: inputImage!) 21 | return imageView 22 | }() 23 | 24 | lazy var slider: UISlider = { 25 | // Create a Slider. 26 | let greenSlider = UISlider(frame: CGRect(x:0, y:0, width:200, height:30)) 27 | greenSlider.layer.position = CGPoint(x:self.view.frame.midX, y:500) 28 | greenSlider.backgroundColor = UIColor.white 29 | greenSlider.layer.cornerRadius = 10.0 30 | greenSlider.layer.shadowOpacity = 0.5 31 | greenSlider.layer.masksToBounds = false 32 | 33 | // Set the minimum and maximum values. 34 | greenSlider.minimumValue = 0 35 | greenSlider.maximumValue = 1 36 | 37 | // Set the position of Slider. 38 | greenSlider.value = 0.5 39 | 40 | // Change the Tint color to the right of the current position of the Slider. 41 | greenSlider.maximumTrackTintColor = UIColor.gray 42 | 43 | // Change the Tint color to the left of the current position of the Slider. 44 | greenSlider.minimumTrackTintColor = UIColor.black 45 | 46 | greenSlider.addTarget(self, action: #selector(onChangeValueSlider(sender:)), for: UIControlEvents.valueChanged) 47 | 48 | return greenSlider 49 | }() 50 | 51 | override func viewDidLoad() { 52 | super.viewDidLoad() 53 | 54 | // Do any additional setup after loading the view. 55 | 56 | // Add UIImageView on view 57 | self.view.addSubview(self.imageView) 58 | 59 | // Add UISlider on view 60 | self.view.addSubview(self.slider) 61 | 62 | self.view.backgroundColor = UIColor(red: 0, green: CGFloat(slider.value), blue: 0, alpha: 1) 63 | } 64 | 65 | override func didReceiveMemoryWarning() { 66 | super.didReceiveMemoryWarning() 67 | // Dispose of any resources that can be recreated. 68 | } 69 | 70 | // Method called when the value of Slider changes 71 | @objc func onChangeValueSlider(sender: UISlider){ 72 | 73 | // Change the green value of the background of the view according to the value of Slider. 74 | self.view.backgroundColor = UIColor(red: 0, green: CGFloat(sender.value), blue: 0, alpha: 1) 75 | 76 | // Instantiate CIFilter with color effect specified. 77 | let colorFilter = CIFilter(name: "CIColorCrossPolynomial") 78 | 79 | // Set the image. 80 | colorFilter!.setValue(self.inputImage, forKey: kCIInputImageKey) 81 | 82 | // Create converted value of RGB. 83 | let r: [CGFloat] = [0.0, CGFloat(sender.value), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 84 | let g: [CGFloat] = [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 85 | let b: [CGFloat] = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 86 | 87 | // Adjust the value. 88 | colorFilter!.setValue(CIVector(values: r, count: 10), forKey: "inputRedCoefficients") 89 | colorFilter!.setValue(CIVector(values: g, count: 10), forKey: "inputGreenCoefficients") 90 | colorFilter!.setValue(CIVector(values: b, count: 10), forKey: "inputBlueCoefficients") 91 | 92 | // Output the image processed by the filter. 93 | let outputImage : CIImage = colorFilter!.outputImage! 94 | 95 | // Set the UIView processed image again. 96 | self.imageView.image = UIImage(ciImage: outputImage) 97 | 98 | // Perform redrawing. 99 | self.imageView.setNeedsDisplay() 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/StepperVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StepperVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class StepperVC: BaseViewController { 12 | 13 | lazy var stepLabel: UILabel = { 14 | // Create Label. 15 | let l: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) 16 | l.backgroundColor = UIColor.blue 17 | l.layer.masksToBounds = true 18 | l.layer.cornerRadius = 75.0 19 | l.textColor = UIColor.white 20 | l.shadowColor = UIColor.gray 21 | l.font = UIFont.systemFont(ofSize: 30.0) 22 | l.textAlignment = NSTextAlignment.center 23 | l.layer.position = CGPoint(x: self.view.bounds.width/2,y: 200) 24 | l.text = "\(self.stepper.value)" 25 | 26 | return l 27 | }() 28 | 29 | lazy var stepper: UIStepper = { 30 | // Create Stepper. 31 | let s: UIStepper = UIStepper() 32 | s.center = CGPoint(x: self.view.frame.width/2, y: 400) 33 | s.backgroundColor = UIColor.gray 34 | s.tintColor = UIColor.white 35 | s.addTarget(self, action: #selector(stepperOnChanged(stepper:)), for: UIControlEvents.valueChanged) 36 | 37 | // Set the minimum value, maximum value, specified value. 38 | s.minimumValue = 0 39 | s.maximumValue = 100 40 | s.value = 50 41 | 42 | // Set the value of the moving value when pressing the button. 43 | s.stepValue = 10 44 | 45 | return s 46 | }() 47 | 48 | override func viewDidLoad() { 49 | super.viewDidLoad() 50 | 51 | // Do any additional setup after loading the view. 52 | 53 | // Add UILabel on view 54 | self.view.addSubview(self.stepLabel) 55 | 56 | // Add UIStepper on view 57 | self.view.addSubview(self.stepper) 58 | } 59 | 60 | override func didReceiveMemoryWarning() { 61 | super.didReceiveMemoryWarning() 62 | // Dispose of any resources that can be recreated. 63 | } 64 | 65 | // It is called when the value of Stepper changes. 66 | @objc func stepperOnChanged(stepper: UIStepper){ 67 | self.stepLabel.text = "\(stepper.value)" 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/SwitchVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwitchVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SwitchVC: BaseViewController { 12 | 13 | lazy var label: UILabel = { 14 | // Create a label to display On / Off. 15 | let label = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) 16 | label.backgroundColor = UIColor.gray 17 | label.layer.masksToBounds = true 18 | label.layer.cornerRadius = 75.0 19 | label.textColor = UIColor.white 20 | label.shadowColor = UIColor.gray 21 | label.font = UIFont.systemFont(ofSize: 30.0) 22 | label.textAlignment = NSTextAlignment.center 23 | label.layer.position = CGPoint(x: self.view.bounds.width/2,y: 200) 24 | label.text = "On" 25 | 26 | return label 27 | }() 28 | 29 | lazy var controlSwitch: UISwitch = { 30 | // Create a Switch. 31 | let swicth: UISwitch = UISwitch() 32 | swicth.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height - 200) 33 | 34 | // Display the border of Swicth. 35 | swicth.tintColor = UIColor.orange 36 | 37 | // Set Switch to On. 38 | swicth.isOn = true 39 | 40 | // Set the event to be called when switching On / Off of Switch. 41 | swicth.addTarget(self, action: #selector(onClickSwitch(sender:)), for: UIControlEvents.valueChanged) 42 | 43 | return swicth 44 | }() 45 | 46 | override func viewDidLoad() { 47 | super.viewDidLoad() 48 | 49 | // Do any additional setup after loading the view. 50 | 51 | // Add UILabel on view 52 | self.view.addSubview(self.label) 53 | 54 | // Add UISwitch on view 55 | self.view.addSubview(self.controlSwitch) 56 | } 57 | 58 | override func didReceiveMemoryWarning() { 59 | super.didReceiveMemoryWarning() 60 | // Dispose of any resources that can be recreated. 61 | } 62 | 63 | @objc func onClickSwitch(sender: UISwitch) { 64 | var text: String! 65 | var color: UIColor! 66 | 67 | if sender.isOn { 68 | text = "On" 69 | color = UIColor.gray 70 | } else { 71 | text = "Off" 72 | color = UIColor.orange 73 | } 74 | 75 | self.label.text = text 76 | self.label.backgroundColor = color 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/TextFieldVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextFieldVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 30.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TextFieldVC: BaseViewController, UITextFieldDelegate { 12 | 13 | lazy var textField: UITextField = { 14 | // Set x, y and width and height to place UITextField. 15 | let width: CGFloat = 250 16 | let height: CGFloat = 50 17 | let posX: CGFloat = (self.view.bounds.width - width)/2 18 | let posY: CGFloat = (self.view.bounds.height - height)/2 19 | 20 | // Create a UITextField. 21 | let textField = UITextField(frame: CGRect(x: posX, y: posY, width: width, height: height)) 22 | 23 | // Substitute the characters to be displayed. 24 | textField.text = "Hello calmone :)" 25 | 26 | // Set Delegate to itself 27 | textField.delegate = self 28 | 29 | // Display frame. 30 | textField.borderStyle = .roundedRect 31 | 32 | // Add clear button. 33 | textField.clearButtonMode = .whileEditing 34 | 35 | return textField 36 | }() 37 | 38 | override func viewDidLoad() { 39 | super.viewDidLoad() 40 | 41 | // Do any additional setup after loading the view. 42 | 43 | // Add UITextField to view 44 | self.view.addSubview(self.textField) 45 | } 46 | 47 | override func didReceiveMemoryWarning() { 48 | super.didReceiveMemoryWarning() 49 | // Dispose of any resources that can be recreated. 50 | } 51 | 52 | // Called just before UITextField is edited 53 | func textFieldDidBeginEditing(_ textField: UITextField) { 54 | print("textFieldDidBeginEditing: \((textField.text) ?? "Empty")") 55 | } 56 | 57 | // Called immediately after UITextField is edited 58 | func textFieldDidEndEditing(_ textField: UITextField) { 59 | print("textFieldDidEndEditing: \((textField.text) ?? "Empty")") 60 | } 61 | 62 | // Called when the line feed button is pressed 63 | func textFieldShouldReturn(_ textField: UITextField) -> Bool { 64 | print("textFieldShouldReturn \((textField.text) ?? "Empty")") 65 | 66 | // Process of closing the Keyboard when the line feed button is pressed. 67 | textField.resignFirstResponder() 68 | 69 | return true 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/TextViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TextViewVC: BaseViewController { 12 | 13 | lazy var textView: UITextView = { 14 | // Create a TextView. 15 | let textView: UITextView = UITextView(frame: CGRect(x:10, y:100, width:self.view.frame.width - 20, height:400)) 16 | 17 | // Set the background of TextView to Orange. 18 | textView.backgroundColor = .orange 19 | 20 | // Set the text to be displayed. 21 | textView.text = "asdlfkjslkdfion1230914098snflsdfn98123n 1234567890 fbaiwerp[q;afnm,vjjsdfa \na\nb\nc\ndefghijklmnopqrstuwxyz \n https://medium.com/@calmone" 22 | 23 | // Round the corners. 24 | textView.layer.masksToBounds = true 25 | 26 | // Set the size of the roundness. 27 | textView.layer.cornerRadius = 20.0 28 | 29 | // Set the thickness of the border. 30 | textView.layer.borderWidth = 1 31 | 32 | // Set the border color to black. 33 | textView.layer.borderColor = UIColor.black.cgColor 34 | 35 | // Set the font. 36 | textView.font = UIFont.systemFont(ofSize: 20.0) 37 | 38 | // Set font color. 39 | textView.textColor = UIColor.black 40 | 41 | // Set left justified. 42 | textView.textAlignment = NSTextAlignment.left 43 | 44 | // Automatically detect links, dates, etc. and convert them to links. 45 | textView.dataDetectorTypes = UIDataDetectorTypes.all 46 | 47 | // Set shadow darkness. 48 | textView.layer.shadowOpacity = 0.5 49 | 50 | // Make text uneditable. 51 | textView.isEditable = false 52 | 53 | return textView 54 | }() 55 | 56 | override func viewDidLoad() { 57 | super.viewDidLoad() 58 | 59 | // Do any additional setup after loading the view. 60 | 61 | // Add UITextView on view 62 | self.view.addSubview(self.textView) 63 | } 64 | 65 | override func didReceiveMemoryWarning() { 66 | super.didReceiveMemoryWarning() 67 | // Dispose of any resources that can be recreated. 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ToggleTouchVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ToggleTouchVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ToggleTouchVC: BaseViewController { 12 | 13 | private var cnt : Float = 0 14 | private var ButtonCnt: Int = 0 15 | private var TimerMergin: Float = 0 16 | private var ignoreBegineTime: Float = 0 17 | 18 | // Make a label for the timer. 19 | lazy var label: UILabel = { 20 | let l = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 21 | l.backgroundColor = UIColor.orange 22 | l.layer.masksToBounds = true 23 | l.layer.cornerRadius = 20.0 24 | l.text = "Time:\(Int(cnt))" 25 | l.textColor = UIColor.white 26 | l.shadowColor = UIColor.gray 27 | l.textAlignment = NSTextAlignment.center 28 | l.layer.position = CGPoint(x: self.view.bounds.width/2, y: 200) 29 | 30 | return l 31 | }() 32 | 33 | // Generate Button. 34 | lazy var button: UIButton = { 35 | let b: UIButton = UIButton() 36 | b.frame = CGRect(x: 0, y: 0, width: 200, height: 50) 37 | b.layer.cornerRadius = 20.0 38 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: 400) 39 | b.backgroundColor = UIColor.red 40 | b.setTitle("Enable / Disable", for: .normal) 41 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 42 | 43 | return b 44 | }() 45 | 46 | override func viewDidLoad() { 47 | super.viewDidLoad() 48 | 49 | // Do any additional setup after loading the view. 50 | 51 | // Add label on view 52 | self.view.addSubview(self.label) 53 | 54 | // Add button on view 55 | self.view.addSubview(self.button) 56 | } 57 | 58 | override func didReceiveMemoryWarning() { 59 | super.didReceiveMemoryWarning() 60 | // Dispose of any resources that can be recreated. 61 | } 62 | 63 | // Method called for every second number specified by NSTimerInterval. 64 | @objc func onUpdate(timer : Timer){ 65 | cnt += 0.1 66 | // Create a character string by specifying the number of digits. 67 | let str = "Time: \(Int(cnt))" 68 | self.label.text = str 69 | 70 | // Difference in time when invalidation started from the current timer time. 71 | TimerMergin = cnt - ignoreBegineTime 72 | 73 | // When the touch event is invalid. 74 | if UIApplication.shared.isIgnoringInteractionEvents { 75 | // It is 5 seconds since it became invalid. 76 | if Int(TimerMergin) == 5 { 77 | print("Invalid touch event") 78 | self.view.backgroundColor = UIColor.blue 79 | 80 | // Enable touch events. 81 | UIApplication.shared.endIgnoringInteractionEvents() 82 | print("Touch event enabled") 83 | } 84 | } 85 | } 86 | 87 | @objc private func onClickButton(sender: UIButton) { 88 | // Number of times the button was pressed. 89 | ButtonCnt += 1 90 | 91 | // When the touch event is valid. 92 | if UIApplication.shared.isIgnoringInteractionEvents == false { 93 | 94 | print("Touch event is valid") 95 | self.view.backgroundColor = UIColor.green 96 | 97 | // Disable the touch event. 98 | UIApplication.shared.beginIgnoringInteractionEvents() 99 | 100 | // Get the time when invalidation began. 101 | ignoreBegineTime = cnt 102 | 103 | print("Touch event was disabled") 104 | print("It will take effect in 5 seconds") 105 | 106 | // Create a timer only when you press the button first. 107 | if ButtonCnt == 1 { 108 | // Make a timer. 109 | // Update interval (0.1 seconds). 110 | Timer.scheduledTimer(timeInterval: 0.1, target: self, 111 | // Method. 112 | selector: #selector(onUpdate(timer:)), 113 | userInfo: nil, 114 | // Whether it will be called many times. 115 | repeats: true) 116 | } 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/ToolBarVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ToolBarVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ToolBarVC: BaseViewController { 12 | 13 | private let toolBarHeight: CGFloat = 44 14 | 15 | lazy var toolBar: UIToolbar = { 16 | // Decide the size of the toolbar. 17 | let tb = UIToolbar(frame: CGRect(x: 0, y: self.view.bounds.size.height - toolBarHeight, width: self.view.bounds.size.width, height: 40.0)) 18 | 19 | // Determine the position of the toolbar. 20 | tb.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0) 21 | 22 | // Decide the color of the toolbar. 23 | tb.barStyle = .blackTranslucent 24 | tb.tintColor = UIColor.white 25 | tb.backgroundColor = UIColor.black 26 | 27 | return tb 28 | }() 29 | 30 | lazy var barButtonGreen: UIBarButtonItem = { 31 | // Generate button 1. 32 | let b: UIBarButtonItem = UIBarButtonItem(title: "Green", style:.plain, target: self, action: #selector(onClickBarButton(sender:))) 33 | b.tag = 1 34 | 35 | return b 36 | }() 37 | 38 | lazy var barButtonBlue: UIBarButtonItem = { 39 | // Generate button 2. 40 | let b: UIBarButtonItem = UIBarButtonItem(title: "Blue", style:.plain, target: self, action: #selector(onClickBarButton(sender:))) 41 | b.tag = 2 42 | 43 | return b 44 | }() 45 | 46 | lazy var barButtonRed: UIBarButtonItem = { 47 | // Generate button 3. 48 | let b: UIBarButtonItem = UIBarButtonItem(title: "Red", style:.plain, target: self, action: #selector(onClickBarButton(sender:))) 49 | b.tag = 3 50 | 51 | return b 52 | }() 53 | 54 | override func viewDidLoad() { 55 | super.viewDidLoad() 56 | 57 | // Do any additional setup after loading the view. 58 | 59 | // Place the button in the tool bar. 60 | self.toolBar.items = [self.barButtonGreen, self.barButtonBlue, self.barButtonRed] 61 | 62 | // Add UIToolBar on view 63 | self.view.addSubview(self.toolBar) 64 | } 65 | 66 | override func didReceiveMemoryWarning() { 67 | super.didReceiveMemoryWarning() 68 | // Dispose of any resources that can be recreated. 69 | } 70 | 71 | // Called when UIBarButtonItem is pressed. 72 | @objc func onClickBarButton(sender: UIBarButtonItem) { 73 | switch sender.tag { 74 | case 1: 75 | self.view.backgroundColor = UIColor.green 76 | case 2: 77 | self.view.backgroundColor = UIColor.blue 78 | case 3: 79 | self.view.backgroundColor = UIColor.red 80 | default: return 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/TransformImageViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransformImageViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 5.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TransformImageViewVC: BaseViewController { 12 | 13 | // Set the image. 14 | let image: UIImage = UIImage(named: "apple.png")! 15 | let imageWidth: CGFloat = 200 16 | let imageHeight: CGFloat = 50 17 | 18 | lazy var scaleDownImageView: UIImageView = { 19 | // Reduce the image (0.5 times) 20 | // Set the coordinates to display. 21 | let downPosX: CGFloat = (self.view.bounds.width - self.imageWidth) / 2 22 | let downPosY: CGFloat = 150 23 | 24 | // Generate UIImageView for display. 25 | let imageView: UIImageView = UIImageView(frame: CGRect(x: downPosX, y: downPosY, width: self.imageWidth, height: self.imageHeight)) 26 | 27 | // Set the image in UIImageView. 28 | imageView.image = self.image 29 | 30 | // Generate an affine matrix for reduction (0.5 times). 31 | imageView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) 32 | 33 | return imageView 34 | }() 35 | 36 | lazy var scaleUpImageView: UIImageView = { 37 | // Enlarge the image (1.2 times) 38 | // Set the coordinates to display. 39 | let upPosX: CGFloat = (self.view.bounds.width - self.imageWidth) / 2 40 | let upPosY: CGFloat = 250 41 | 42 | // Generate UIImageView for display. 43 | let imageView: UIImageView = UIImageView(frame: CGRect(x: upPosX, y: upPosY, width: self.imageWidth, height: self.imageHeight)) 44 | 45 | // Set the image in UIImageView. 46 | imageView.image = self.image 47 | 48 | // Generate an affine matrix for enlarge (1.2 times). 49 | imageView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) 50 | 51 | return imageView 52 | }() 53 | 54 | lazy var rotateImageView: UIImageView = { 55 | // Rotate the image. 56 | // Set the coordinates to display. 57 | let rotatePosX: CGFloat = (self.view.bounds.width - self.imageWidth) / 2 58 | let rotatePosY: CGFloat = 450 59 | 60 | // Generate UIImageView for display. 61 | let imageView: UIImageView = UIImageView(frame: CGRect(x: rotatePosX, y: rotatePosY, width: self.imageWidth, height: self.imageHeight)) 62 | 63 | // Set the image in UIImageView. 64 | imageView.image = self.image 65 | 66 | // Specify rotation angle with radian (30 degrees). 67 | let angle: CGFloat = CGFloat((30.0 * Double.pi) / 180.0) 68 | 69 | // Generate an affine matrix for rotation. 70 | imageView.transform = CGAffineTransform(rotationAngle: angle) 71 | 72 | return imageView 73 | }() 74 | 75 | lazy var reverseImageView: UIImageView = { 76 | // Flip the image. 77 | // Set the coordinates to display. 78 | let reversePosX: CGFloat = (self.view.bounds.width - self.imageWidth) / 2 79 | let reversePosY: CGFloat = 550 80 | 81 | // Generate UIImageView for display. 82 | let imageView: UIImageView = UIImageView(frame: CGRect(x: reversePosX, y: reversePosY, width: self.imageWidth, height: self.imageHeight)) 83 | 84 | // Set the image in UIImageView. 85 | imageView.image = self.image 86 | 87 | // Generate an affine matrix for reduction (0.5 times). 88 | imageView.transform = imageView.transform.scaledBy(x: -1.0, y: 1.0) 89 | 90 | return imageView 91 | }() 92 | 93 | override func viewDidLoad() { 94 | super.viewDidLoad() 95 | 96 | // Do any additional setup after loading the view. 97 | 98 | // Add UIImageViews on view 99 | self.view.addSubview(self.scaleDownImageView) 100 | self.view.addSubview(self.scaleUpImageView) 101 | self.view.addSubview(self.rotateImageView) 102 | self.view.addSubview(self.reverseImageView) 103 | } 104 | 105 | override func didReceiveMemoryWarning() { 106 | super.didReceiveMemoryWarning() 107 | // Dispose of any resources that can be recreated. 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/TransitionsViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransitionsViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TransitionsViewVC: BaseViewController { 12 | 13 | lazy var transitionView: UIView = { 14 | // Generate view. 15 | let v = UIView(frame: self.view.frame) 16 | v.backgroundColor = UIColor.orange 17 | v.isHidden = false 18 | v.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 19 | 20 | return v 21 | }() 22 | 23 | lazy var button: UIButton = { 24 | // Generate button. 25 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50)) 26 | b.backgroundColor = UIColor.red 27 | b.layer.masksToBounds = true 28 | b.layer.cornerRadius = 20.0 29 | b.setTitle("Transition", for: .normal) 30 | b.setTitleColor(UIColor.white, for: .normal) 31 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 32 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 33 | 34 | return b 35 | }() 36 | 37 | // View switching flag. 38 | var viewFlag = true 39 | 40 | override func viewDidLoad() { 41 | super.viewDidLoad() 42 | 43 | // Do any additional setup after loading the view. 44 | 45 | // Add transitionView on view 46 | self.view.addSubview(self.transitionView) 47 | // Add button on view 48 | self.view.addSubview(self.button) 49 | } 50 | 51 | override func didReceiveMemoryWarning() { 52 | super.didReceiveMemoryWarning() 53 | // Dispose of any resources that can be recreated. 54 | } 55 | 56 | // Button event 57 | @objc func onClickButton(sender: UIButton) { 58 | // Flag is true. 59 | if viewFlag { 60 | // Animation processing. 61 | // Which view will transition from? 62 | UIView.transition(from: self.view, 63 | // view of the transition destination. 64 | to: self.transitionView, 65 | // number of seconds (1 second). 66 | duration: 1.0, 67 | // Set the transition. 68 | options: UIViewAnimationOptions.transitionCurlUp, 69 | // Processing when the animation is completed. 70 | completion: { (Bool) -> Void in 71 | print("self.view -> transitionView") 72 | // Add a button to transitionView. 73 | self.transitionView.addSubview(self.button) 74 | }) 75 | // Fold the flag. 76 | viewFlag = false 77 | } else { 78 | UIView.transition(from: self.transitionView, 79 | to: self.view, 80 | duration: 1.0, 81 | options: UIViewAnimationOptions.transitionFlipFromLeft, 82 | completion: { (Bool) -> Void in 83 | print("transitionView -> self.view") 84 | // Add button on view 85 | self.view.addSubview(self.button) 86 | }) 87 | // Set a flag. 88 | viewFlag = true 89 | } 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/TransparencyImageVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransparencyImageVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 17.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TransparencyImageVC: BaseViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Image settings. 19 | let image: UIImage = UIImage(named:"vertical.jpeg")! 20 | 21 | // Specify the resized UIImage and make UIImageView. 22 | let imageView = UIImageView(image: image.ResizeUIImage(width: self.view.frame.maxX, height: self.view.frame.maxY)) 23 | 24 | // Set alpha 25 | imageView.alpha = 0.5 26 | 27 | // Add imageView on view 28 | self.view.addSubview(imageView) 29 | } 30 | 31 | override func didReceiveMemoryWarning() { 32 | super.didReceiveMemoryWarning() 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | } 37 | 38 | fileprivate extension UIImage { 39 | 40 | // Create a class method of Resize. 41 | func ResizeUIImage(width: CGFloat, height: CGFloat) -> UIImage! { 42 | 43 | // Prepare the context of the specified image size. 44 | UIGraphicsBeginImageContext(CGSize(width: width, height: height)) 45 | 46 | // Draw the image in the context. 47 | self.draw(in: CGRect(x: 0, y: 0, width: width, height: height)) 48 | 49 | // Create a UIImage from the context. 50 | let newImage = UIGraphicsGetImageFromCurrentImageContext() 51 | 52 | // Close the context. 53 | UIGraphicsEndImageContext() 54 | 55 | return newImage 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UIBezierPath/BezierPathVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BezierPathVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class BezierPathVC: BaseViewController { 12 | 13 | lazy var segcon: UISegmentedControl = { 14 | // Generate SegmentedController. 15 | let sc = UISegmentedControl(items: ["Circle", "Rectangle", "Line"]) 16 | sc.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height - 50) 17 | sc.tintColor = UIColor.blue 18 | sc.addTarget(self, action: #selector(changedValue(sender:)), for: UIControlEvents.valueChanged) 19 | 20 | return sc 21 | }() 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | 26 | // Do any additional setup after loading the view. 27 | 28 | // Add segmentedController on view 29 | self.view.addSubview(segcon) 30 | } 31 | 32 | override func didReceiveMemoryWarning() { 33 | super.didReceiveMemoryWarning() 34 | // Dispose of any resources that can be recreated. 35 | } 36 | 37 | // A method called when the value of SegmentedController changes. 38 | @objc func changedValue(sender: UISegmentedControl) { 39 | var drawView: UIView! 40 | 41 | // Create an instance of each class according to the value of SegmentedController. 42 | switch(sender.selectedSegmentIndex) { 43 | case 0: drawView = DrawCircleView(frame: CGRect(x: 0, y: 100, width: 300, height: 300)) 44 | case 1: drawView = DrawRectangleView(frame: CGRect(x: 0, y: 100, width: 300, height: 300)) 45 | case 2: drawView = DrawLineView(frame: CGRect(x:0, y: 100, width: 300, height: 300)) 46 | default: print("error") 47 | } 48 | 49 | // Set the center of drawing for drawing. 50 | drawView.center = CGPoint(x: self.view.frame.width/2, y: 300) 51 | drawView.backgroundColor = UIColor.white 52 | 53 | // Added drawing view to view. 54 | self.view.addSubview(drawView) 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UIBezierPath/DrawCircleView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrawCircleView.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DrawCircleView: UIView { 12 | 13 | override init(frame: CGRect) { 14 | super.init(frame: frame) 15 | } 16 | 17 | required init(coder aDecoder: NSCoder) { 18 | fatalError("init(coder:) has not been implemented") 19 | } 20 | 21 | // It is automatically called when it becomes necessary to update the display. 22 | override func draw(_ rect: CGRect) { 23 | // Setting of view. 24 | self.layer.borderColor = UIColor.brown.cgColor 25 | self.layer.borderWidth = 0.5 26 | self.layer.cornerRadius = 10.0 27 | self.layer.masksToBounds = true 28 | 29 | let circlePoint = CGPoint(x:100, y:100) 30 | 31 | // Generate BezierPath of Yen 32 | let circle: UIBezierPath = UIBezierPath(arcCenter: circlePoint, 33 | // Radius. 34 | radius: 70.0, 35 | // First angle. 36 | startAngle: 0.0, 37 | // Final angle. 38 | endAngle: CGFloat(M_PI*2/4), 39 | // Counterclockwise. 40 | clockwise: false) 41 | 42 | // Set the line color to red. 43 | UIColor.red.setStroke() 44 | 45 | // Set the fill color to yellow. 46 | UIColor.yellow.setFill() 47 | 48 | // Fill the closed inside with a line. 49 | circle.fill() 50 | 51 | // Set the thickness of the line. 52 | circle.lineWidth = 3.0 53 | 54 | // Drawing. 55 | circle.stroke() 56 | 57 | // Generate BezierPath of an ellipse. 58 | let oval: UIBezierPath = UIBezierPath(ovalIn: CGRect(x:130, y:150, width:150, height:100)) 59 | UIColor.blue.setStroke() 60 | UIColor.gray.setFill() 61 | oval.fill() 62 | oval.lineWidth = 2.0 63 | 64 | // Drawing. 65 | oval.stroke() 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UIBezierPath/DrawLineView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrawLineView.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DrawLineView: UIView { 12 | 13 | override init(frame: CGRect) { 14 | super.init(frame: frame) 15 | } 16 | 17 | required init(coder aDecoder: NSCoder) { 18 | fatalError("init(coder:) has not been implemented") 19 | } 20 | 21 | // It is automatically called when it becomes necessary to update the display. 22 | override func draw(_ rect: CGRect) { 23 | // Setting of view. 24 | self.layer.borderColor = UIColor.brown.cgColor 25 | self.layer.borderWidth = 0.5 26 | self.layer.cornerRadius = 10.0 27 | self.layer.masksToBounds = true 28 | 29 | // Generate BezierPath. 30 | let line: UIBezierPath = UIBezierPath() 31 | 32 | // Set the line color to blue. 33 | UIColor.red.setStroke() 34 | 35 | // Set the start point. 36 | line.move(to: CGPoint.zero) 37 | 38 | // Set the next point. 39 | line.addLine(to: CGPoint(x: 50, y: 150)) 40 | line.addLine(to: CGPoint(x: 200, y: 100)) 41 | 42 | // Set the end point. 43 | line.addLine(to: CGPoint(x: self.bounds.width, y: self.bounds.height)) 44 | 45 | // Connect start and end points and close. 46 | line.close() 47 | 48 | // Set the fill color. 49 | UIColor.yellow.setFill() 50 | 51 | // Fill the closed inside with a line. 52 | line.fill() 53 | 54 | // Set the thickness of the line. 55 | line.lineWidth = 3.0 56 | 57 | // Drawing. 58 | line.stroke() 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UIBezierPath/DrawRectangleView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrawRectangleView.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 14.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DrawRectangleView: UIView { 12 | 13 | override init(frame: CGRect) { 14 | super.init(frame: frame) 15 | } 16 | 17 | required init(coder aDecoder: NSCoder) { 18 | fatalError("init(coder:) has not been implemented") 19 | } 20 | 21 | // It is automatically called when it becomes necessary to update the display. 22 | override func draw(_ rect: CGRect) { 23 | // Setting of view. 24 | self.layer.borderColor = UIColor.brown.cgColor 25 | self.layer.borderWidth = 0.5 26 | self.layer.cornerRadius = 10.0 27 | self.layer.masksToBounds = true 28 | 29 | // Generate a rectangular UIBezierPath. 30 | let rect1: UIBezierPath = UIBezierPath(rect: CGRect(x: 5, y: 5, width: 290, height: 290)) 31 | 32 | // Set the line color to blue. 33 | UIColor.blue.setStroke() 34 | 35 | // Set the thickness of the line. 36 | rect1.lineWidth = 1.0 37 | 38 | // Drawing. 39 | rect1.stroke() 40 | 41 | // Generate round rectangular UIBezierPath. 42 | let rect2: UIBezierPath = UIBezierPath(roundedRect: CGRect(x: 50, y: 50, width: 200, height: 100), 43 | // Round all the corners. 44 | byRoundingCorners: UIRectCorner.allCorners, 45 | // Set the degree to round. 46 | cornerRadii: CGSize(width: 5.0, height: 5.0)) 47 | 48 | // Set the line color to orange. 49 | UIColor.orange.setStroke() 50 | 51 | // Set the fill color to yellow. 52 | UIColor.yellow.setFill() 53 | 54 | // Fill color. 55 | rect2.fill() 56 | 57 | // Set the thickness of the line. 58 | rect2.lineWidth = 3.0 59 | 60 | // Drawing. 61 | rect2.stroke() 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UINavigationBar/FirstNavigationVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FirstNavigationVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FirstNavigationVC: UIViewController { 12 | 13 | lazy var button: UIButton = { 14 | // Create Button 15 | let b = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50)) 16 | b.backgroundColor = UIColor.orange 17 | b.layer.masksToBounds = true 18 | b.setTitle("button", for: .normal) 19 | b.layer.cornerRadius = 20.0 20 | b.layer.position = CGPoint(x: self.view.bounds.width/2, y:200) 21 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 22 | 23 | return b 24 | }() 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | // Do any additional setup after loading the view. 30 | 31 | // Define the background color of View. 32 | self.view.backgroundColor = UIColor(white: 0.9, alpha: 1.0) 33 | 34 | // Add button on view 35 | self.view.addSubview(self.button) 36 | 37 | // Create a BarButtonItem. 38 | let barButton_1 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.camera, target: self, action: #selector(onClickBarButton(sender:))) 39 | let barButton_2 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(onClickBarButton(sender:))) 40 | let barButton_3 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(onClickBarButton(sender:))) 41 | barButton_3.tag = 99 42 | 43 | // Store the button to the right of the Bar in the array. 44 | let rightButtons: [UIBarButtonItem] = [barButton_1, barButton_2] 45 | 46 | // Display NavigationBar. 47 | self.navigationController?.setNavigationBarHidden(false, animated: false) 48 | 49 | // Set the title. 50 | self.navigationItem.title = "First View" 51 | 52 | // Set the prompt. 53 | self.navigationItem.prompt = "Prompt" 54 | 55 | // Place multiple on the right side of Bar. 56 | self.navigationItem.setRightBarButtonItems(rightButtons, animated: true) 57 | 58 | // Place it on the left side of Bar. 59 | self.navigationItem.setLeftBarButton(barButton_3, animated: true) 60 | } 61 | 62 | override func didReceiveMemoryWarning() { 63 | super.didReceiveMemoryWarning() 64 | // Dispose of any resources that can be recreated. 65 | } 66 | 67 | // Called when the bar button is pressed 68 | @objc private func onClickBarButton(sender: UIBarButtonItem) { 69 | if sender.tag == 99 { 70 | self.navigationController?.popViewController(animated: true) 71 | } 72 | print("onClickBarButton:") 73 | } 74 | 75 | // Called when the button is pressed 76 | @objc private func onClickButton(sender: UIButton) { 77 | let secondViewController = SecondNavigationVC() 78 | self.navigationController?.pushViewController(secondViewController, animated: true) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UINavigationBar/SecondNavigationVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondNavigationVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 10.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondNavigationVC: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Set the controller's title. 19 | self.title = "Second View" 20 | 21 | // Define the background color of View. 22 | self.view.backgroundColor = UIColor.green 23 | } 24 | 25 | override func didReceiveMemoryWarning() { 26 | super.didReceiveMemoryWarning() 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UINavigationViewController/FirstViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FirstViewController: UIViewController { 12 | 13 | lazy var button: UIButton = { 14 | // Generate UIButton. 15 | let width: CGFloat = 300 16 | let height: CGFloat = 100 17 | let posX: CGFloat = (self.view.bounds.width - width)/2 18 | let posY: CGFloat = 200 19 | let button = UIButton(frame: CGRect(x: posX, y: posY, width: width, height: height)) 20 | 21 | button.backgroundColor = UIColor.orange 22 | button.layer.masksToBounds = true 23 | button.layer.cornerRadius = 20.0 24 | button.setTitle("Move to SecondView.", for: .normal) 25 | button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside) 26 | 27 | return button 28 | }() 29 | 30 | override func viewDidLoad() { 31 | super.viewDidLoad() 32 | 33 | // Do any additional setup after loading the view. 34 | 35 | // Set the controller's title. 36 | self.navigationItem.prompt = "Fisrt View" 37 | 38 | // Set the background color of the view to Cyan. 39 | self.view.backgroundColor = .orange 40 | 41 | // Add UIButton on view 42 | self.view.addSubview(self.button) 43 | } 44 | 45 | override func didReceiveMemoryWarning() { 46 | super.didReceiveMemoryWarning() 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | // UIButton Event. 51 | @objc private func buttonPressed(_ sender: Any) { 52 | // Define the view to move to. 53 | let secondViewController = SecondViewController() 54 | 55 | // Move to SecondView. 56 | self.navigationController?.pushViewController(secondViewController, animated: true) 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UINavigationViewController/SecondViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Set the controller's title. 19 | self.navigationItem.prompt = "Second View" 20 | 21 | // Set the background color of the view to Cyan. 22 | self.view.backgroundColor = .green 23 | 24 | } 25 | 26 | override func didReceiveMemoryWarning() { 27 | super.didReceiveMemoryWarning() 28 | // Dispose of any resources that can be recreated. 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UITabBarController/FirstTabBarViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FirstTabBarViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FirstTabBarViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | } 18 | 19 | override func didReceiveMemoryWarning() { 20 | super.didReceiveMemoryWarning() 21 | // Dispose of any resources that can be recreated. 22 | } 23 | 24 | init() { 25 | super.init(nibName: nil, bundle: nil) 26 | 27 | // Set the background color of the view to Orange. 28 | self.view.backgroundColor = .orange 29 | 30 | // Define the tabBarItem's icon as Featured and Tag as 1. 31 | self.tabBarItem = UITabBarItem(tabBarSystemItem: .featured, tag: 1) 32 | } 33 | 34 | required init?(coder aDecoder: NSCoder) { 35 | super.init(coder: aDecoder) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UITabBarController/RootTabBarViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RootTabBarViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class RootTabBarViewController: UITabBarController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | 18 | // Set the controller's title. 19 | self.navigationItem.prompt = "UITabBarController" 20 | } 21 | 22 | override func didReceiveMemoryWarning() { 23 | super.didReceiveMemoryWarning() 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | init() { 28 | super.init(nibName: nil, bundle: nil) 29 | 30 | // Generate an instance of the ViewController to set on the Tab. 31 | let firstTab: UIViewController = FirstTabBarViewController() 32 | let secondTab: UIViewController = SecondTabBarViewController() 33 | 34 | // Create an Array of Tables with Tabs as Elements. 35 | let tabs = NSArray(objects: firstTab, secondTab) 36 | 37 | // Set the ViewController. 38 | self.setViewControllers(tabs as? [UIViewController], animated: false) 39 | } 40 | 41 | required init?(coder aDecoder: NSCoder) { 42 | fatalError("init(coder:) has not been implemented") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UITabBarController/SecondTabBarViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SecondTabBarViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 3.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SecondTabBarViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | } 18 | 19 | override func didReceiveMemoryWarning() { 20 | super.didReceiveMemoryWarning() 21 | // Dispose of any resources that can be recreated. 22 | } 23 | 24 | init() { 25 | super.init(nibName: nil, bundle: nil) 26 | 27 | // Set the background color of the view to Green. 28 | self.view.backgroundColor = .green 29 | 30 | // Define the tabBarItem's icon as Featured and Tag as 2. 31 | self.tabBarItem = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 2) 32 | } 33 | 34 | required init?(coder aDecoder: NSCoder) { 35 | super.init(coder: aDecoder) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UiViewController/PushFirstVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PushFirstVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 6.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PushFirstVC: BaseViewController { 12 | 13 | // Generate UIButton 14 | lazy var nextButton: UIButton = { 15 | // Create a button. 16 | let button: UIButton = UIButton(frame: CGRect(x: 0,y: 0, width: 120, height: 50)) 17 | button.backgroundColor = UIColor.red 18 | button.layer.masksToBounds = true 19 | button.setTitle("Next", for: .normal) 20 | button.layer.cornerRadius = 20.0 21 | button.layer.position = CGPoint(x: self.view.bounds.width/2 , y:self.view.bounds.height-50) 22 | button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside) 23 | 24 | return button 25 | }() 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | 30 | // Do any additional setup after loading the view. 31 | 32 | // Set the background color to Green. 33 | self.view.backgroundColor = .green 34 | 35 | //Add UIButton on view 36 | self.view.addSubview(self.nextButton) 37 | } 38 | 39 | override func didReceiveMemoryWarning() { 40 | super.didReceiveMemoryWarning() 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | // Button event. 45 | @objc private func buttonPressed(_ sender: Any) { 46 | // Define the View to transition. 47 | let secondVC: UIViewController = PushSecondVC(componentName: "SecondVC") 48 | 49 | // Move the View. 50 | self.navigationController?.pushViewController(secondVC, animated: true) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/UiViewController/PushSecondVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PushSecondVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 6.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PushSecondVC: BaseViewController { 12 | 13 | // Generate UIButton 14 | lazy var backButton: UIButton = { 15 | // Create a button. 16 | let button: UIButton = UIButton(frame: CGRect(x: 0,y: 0, width: 120, height: 50)) 17 | button.backgroundColor = .red 18 | button.layer.masksToBounds = true 19 | button.setTitle("Back", for: .normal) 20 | button.layer.cornerRadius = 20.0 21 | button.layer.position = CGPoint(x: self.view.bounds.width/2 , y:self.view.bounds.height-50) 22 | button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside) 23 | 24 | return button 25 | }() 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | 30 | // Do any additional setup after loading the view. 31 | 32 | // Set the background color to Green. 33 | self.view.backgroundColor = .orange 34 | 35 | // Add UIButton on view 36 | self.view.addSubview(self.backButton) 37 | } 38 | 39 | override func didReceiveMemoryWarning() { 40 | super.didReceiveMemoryWarning() 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | // Button event. 45 | @objc private func buttonPressed(_ sender: Any) { 46 | // Move the View. 47 | self.navigationController?.popViewController(animated: true) 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/WebPdfFileVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebPdfFileVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class WebPdfFileVC: BaseViewController { 12 | 13 | // Generate webView 14 | lazy var webView: UIWebView = { 15 | let myWebView = UIWebView() 16 | myWebView.frame = self.view.bounds 17 | 18 | // Get the path of the file managed by the project. 19 | let path: String = Bundle.main.path(forResource: "iOS_Security_Guide", ofType: "pdf")! 20 | 21 | let url = URL(fileURLWithPath: path) 22 | let request = URLRequest(url: url) 23 | 24 | // Request loading. 25 | myWebView.loadRequest(request as URLRequest) 26 | 27 | return myWebView 28 | }() 29 | 30 | override func viewDidLoad() { 31 | super.viewDidLoad() 32 | 33 | // Do any additional setup after loading the view. 34 | 35 | // Add webView on view 36 | self.view.addSubview(webView) 37 | } 38 | 39 | override func didReceiveMemoryWarning() { 40 | super.didReceiveMemoryWarning() 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/WebPdfVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebPdfVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 21.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class WebPdfVC: BaseViewController { 12 | 13 | // Generate button 14 | lazy var button: UIButton = { 15 | let b: UIButton = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 16 | b.layer.cornerRadius = 20.0 17 | b.layer.masksToBounds = true 18 | b.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height - 50) 19 | b.backgroundColor = UIColor.orange 20 | b.setTitle("Open PDF", for: UIControlState.normal) 21 | b.setTitleColor(UIColor.white, for: UIControlState.normal) 22 | b.addTarget(self, action: #selector(onClickButton(_:)), for: UIControlEvents.touchUpInside) 23 | 24 | return b 25 | }() 26 | 27 | lazy var webView: UIWebView = { 28 | let wv = UIWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)) 29 | wv.delegate = self 30 | wv.scalesPageToFit = true 31 | wv.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2) 32 | 33 | return wv 34 | }() 35 | 36 | lazy var indicator: UIActivityIndicatorView = { 37 | let iv = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) 38 | iv.center = self.view.center 39 | iv.hidesWhenStopped = true 40 | iv.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray 41 | 42 | return iv 43 | }() 44 | 45 | var PDFurl: URL! 46 | var request: URLRequest! 47 | 48 | override func viewDidLoad() { 49 | super.viewDidLoad() 50 | 51 | // Do any additional setup after loading the view. 52 | 53 | // Add button on view 54 | self.view.addSubview(button) 55 | 56 | PDFurl = URL(string: "https://developer.apple.com/programs/terms/apple_developer_agreement.pdf") 57 | request = URLRequest(url: PDFurl) 58 | } 59 | 60 | override func didReceiveMemoryWarning() { 61 | super.didReceiveMemoryWarning() 62 | // Dispose of any resources that can be recreated. 63 | } 64 | 65 | } 66 | 67 | extension WebPdfVC: UIWebViewDelegate { 68 | // Animation of the indicator is started. 69 | func startAnimation() { 70 | 71 | // Display NetworkActivityIndicator. 72 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 73 | 74 | // Display UIACtivityIndicator. 75 | if !indicator.isAnimating { 76 | indicator.startAnimating() 77 | } 78 | 79 | // Add an indicator to view. 80 | self.view.addSubview(indicator) 81 | } 82 | 83 | // Animation of the indicator is finished. 84 | func stopAnimation() { 85 | // Hide NetworkActivityIndicator. 86 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 87 | 88 | // Hide UIACtivityIndicator. 89 | if indicator.isAnimating { 90 | indicator.stopAnimating() 91 | } 92 | } 93 | 94 | // A method called when the Button is pressed. 95 | @objc private func onClickButton(_ sender: UIButton) { 96 | // Start loading WebView. 97 | webView.loadRequest(request) 98 | 99 | // Add WebView to view. 100 | self.view.addSubview(webView) 101 | } 102 | 103 | // A method called when WebView's load is started. 104 | func webViewDidStartLoad(_ webView: UIWebView) { 105 | print("load started") 106 | startAnimation() 107 | } 108 | 109 | // A method called when WebView's load exits. 110 | func webViewDidFinishLoad(_ webView: UIWebView) { 111 | print("load finished") 112 | stopAnimation() 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/WebViewVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 1.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class WebViewVC: BaseViewController, UIWebViewDelegate { 12 | 13 | lazy var webView: UIWebView = { 14 | // Generate WebView. 15 | let webView = UIWebView() 16 | 17 | // Set Delegate to itself. 18 | webView.delegate = self 19 | 20 | // Set the size of WebView. 21 | webView.frame = self.view.bounds 22 | 23 | // Set the URL. 24 | let url: URL = URL(string: "https://medium.com/@calmone")! 25 | 26 | // Issue a rev. 27 | let request: NSURLRequest = NSURLRequest(url: url) 28 | 29 | // Issue the request. 30 | webView.loadRequest(request as URLRequest) 31 | 32 | return webView 33 | }() 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | 38 | // Do any additional setup after loading the view. 39 | 40 | // Add UIWebView on view 41 | self.view.addSubview(self.webView) 42 | } 43 | 44 | override func didReceiveMemoryWarning() { 45 | super.didReceiveMemoryWarning() 46 | // Dispose of any resources that can be recreated. 47 | } 48 | 49 | // Called when all pages have been read. 50 | func webViewDidFinishLoad(_ webView: UIWebView) { 51 | print("webViewDidFinishLoad") 52 | } 53 | 54 | // Called when the Page starts loading. 55 | func webViewDidStartLoad(_ webView: UIWebView) { 56 | print("webViewDidStartLoad") 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /UIKit component handling/ComponentViewController/WindowVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WindowVC.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 8. 9.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class WindowVC: BaseViewController { 12 | 13 | lazy var window: UIWindow = { 14 | let w = UIWindow() 15 | // Set the background to white. 16 | w.backgroundColor = UIColor.white 17 | w.frame = CGRect(x: 0, y: 0, width: 200, height: 250) 18 | w.layer.position = CGPoint(x:self.view.frame.width/2, y:self.view.frame.height/2) 19 | w.alpha = 0.8 20 | w.layer.cornerRadius = 20 21 | 22 | // Set window to keyWindow. 23 | w.makeKey() 24 | 25 | // Display window. 26 | w.makeKeyAndVisible() 27 | 28 | w.isHidden = true 29 | 30 | return w 31 | }() 32 | 33 | lazy var windowButton: UIButton = { 34 | // Create a button. 35 | let b = UIButton() 36 | b.frame = CGRect(x: 0, y: 0, width: 100, height: 60) 37 | b.backgroundColor = UIColor.orange 38 | b.setTitle("Close", for: .normal) 39 | b.setTitleColor(UIColor.white, for: .normal) 40 | b.layer.masksToBounds = true 41 | b.layer.cornerRadius = 20.0 42 | b.layer.position = CGPoint(x: self.window.frame.width/2, y: self.window.frame.height-50) 43 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 44 | 45 | return b 46 | }() 47 | 48 | lazy var button: UIButton = { 49 | // Create a button. 50 | let b = UIButton() 51 | b.frame = CGRect(x:0, y:0, width:60, height:60) 52 | b.backgroundColor = UIColor.red 53 | b.setTitle("Dialog", for: .normal) 54 | b.setTitleColor(UIColor.white, for: .normal) 55 | b.layer.masksToBounds = true 56 | b.layer.cornerRadius = 30.0 57 | b.layer.position = CGPoint(x:self.view.frame.width/2, y:self.view.frame.height-100) 58 | b.addTarget(self, action: #selector(onClickButton(sender:)), for: .touchUpInside) 59 | 60 | return b 61 | }() 62 | 63 | lazy var imageView: UIImageView = { 64 | let iv = UIImageView(image: self.image) 65 | // Calculate the scale of the image. 66 | let scale = self.view.frame.width / self.image.size.width 67 | iv.frame = CGRect(x: 0, y: 50, width: self.image.size.width*scale, height: self.image.size.height*scale) 68 | return iv 69 | }() 70 | 71 | // Set the image on the background. 72 | lazy var image: UIImage = UIImage(named: "vertical.jpeg")! 73 | 74 | override func viewDidLoad() { 75 | super.viewDidLoad() 76 | 77 | // Do any additional setup after loading the view. 78 | 79 | // Add UIImageView on view 80 | self.view.addSubview(self.imageView) 81 | 82 | // Add UIButton on view 83 | self.view.addSubview(self.button) 84 | 85 | makeWindow() 86 | } 87 | 88 | override func didReceiveMemoryWarning() { 89 | super.didReceiveMemoryWarning() 90 | // Dispose of any resources that can be recreated. 91 | } 92 | 93 | // Create your own window 94 | func makeWindow(){ 95 | // Create a TextView. 96 | let textView: UITextView = UITextView(frame: CGRect(x: 10, y: 10, width: self.window.frame.width - 20, height:150)) 97 | textView.backgroundColor = UIColor.clear 98 | textView.text = "I won’t go into details about recording a video or taking a photo, this article focuses on the UI part of building a custom camera. Hopefully, I will write an article about recording videos and taking photos soon." 99 | textView.font = UIFont.systemFont(ofSize: 15.0) 100 | textView.textColor = UIColor.black 101 | textView.textAlignment = NSTextAlignment.left 102 | textView.isEditable = false 103 | 104 | self.window.addSubview(self.windowButton) 105 | self.window.addSubview(textView) 106 | } 107 | 108 | 109 | // Button event 110 | @objc func onClickButton(sender: UIButton) { 111 | if sender == self.windowButton { 112 | self.window.isHidden = true 113 | } else if sender == self.button { 114 | self.window.isHidden = false 115 | } 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /UIKit component handling/Support/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /UIKit component handling/Support/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /UIKit component handling/Support/BaseViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaseViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class BaseViewController: UIViewController { 12 | 13 | // var componentName: String! 14 | 15 | // private lazy var titleLabel: UILabel = { 16 | // let l = UILabel() 17 | // l.text = self.componentName 18 | // l.numberOfLines = 0 19 | // l.textAlignment = .center 20 | // l.font = .systemFont(ofSize: 20, weight: .bold) 21 | // l.translatesAutoresizingMaskIntoConstraints = false 22 | // return l 23 | // }() 24 | 25 | // lazy var contentView: UIView = { 26 | // let v = UIView() 27 | // v.backgroundColor = .orange 28 | // v.translatesAutoresizingMaskIntoConstraints = false 29 | // return v 30 | // }() 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | // Do any additional setup after loading the view. 36 | setupView() 37 | // self.title = self.componentName 38 | } 39 | 40 | override func didReceiveMemoryWarning() { 41 | super.didReceiveMemoryWarning() 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | init(componentName: String) { 46 | super.init(nibName: nil, bundle: nil) 47 | // self.title = componentName 48 | self.navigationItem.prompt = componentName 49 | // self.componentName = componentName 50 | } 51 | 52 | required init?(coder aDecoder: NSCoder) { 53 | fatalError("init(coder:) has not been implemented") 54 | } 55 | 56 | func appDelegate() -> AppDelegate? { 57 | guard let app = UIApplication.shared.delegate as? AppDelegate else { return nil } 58 | return app 59 | } 60 | 61 | private func setupView() { 62 | self.view.backgroundColor = UIColor(white: 0.9, alpha: 1.0) 63 | // self.view.addSubview(self.titleLabel) 64 | // self.view.addSubview(self.contentView) 65 | 66 | // Add Constraints 67 | // addConstraintsForTitleLabel() 68 | // addConstraintsForContentView() 69 | } 70 | 71 | // private func addConstraintsForTitleLabel() { 72 | // let leading: NSLayoutConstraint = NSLayoutConstraint(item: self.titleLabel, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1, constant: 0) 73 | // let top: NSLayoutConstraint = NSLayoutConstraint(item: self.titleLabel, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .topMargin, multiplier: 1, constant: 0) 74 | // let trailing: NSLayoutConstraint = NSLayoutConstraint(item: self.titleLabel, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1, constant: 0) 75 | // let height: NSLayoutConstraint = NSLayoutConstraint(item: self.titleLabel, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 0.08, constant: 0) 76 | // 77 | // NSLayoutConstraint.activate([leading, top, trailing, height]) 78 | // } 79 | // 80 | // private func addConstraintsForContentView() { 81 | // let leading: NSLayoutConstraint = NSLayoutConstraint(item: self.contentView, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1, constant: 0) 82 | // let top: NSLayoutConstraint = NSLayoutConstraint(item: self.contentView, attribute: .top, relatedBy: .equal, toItem: self.titleLabel, attribute: .bottom, multiplier: 1, constant: 0) 83 | // let trailing: NSLayoutConstraint = NSLayoutConstraint(item: self.contentView, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1, constant: 0) 84 | // let bottom: NSLayoutConstraint = NSLayoutConstraint(item: self.contentView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottomMargin, multiplier: 1, constant: 0) 85 | // 86 | // NSLayoutConstraint.activate([leading, top, trailing, bottom]) 87 | // } 88 | 89 | 90 | /* 91 | // MARK: - Navigation 92 | 93 | // In a storyboard-based application, you will often want to do a little preparation before navigation 94 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 95 | // Get the new view controller using segue.destinationViewController. 96 | // Pass the selected object to the new view controller. 97 | } 98 | */ 99 | 100 | } 101 | -------------------------------------------------------------------------------- /UIKit component handling/Support/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSPhotoLibraryAddUsageDescription 24 | Please activate it. 25 | NSPhotoLibraryUsageDescription 26 | Please activate it. 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /UIKit component handling/Support/UIKit_component_handling.xcdatamodeld/UIKit_component_handling.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIKit component handling/Support/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calmone/iOS-UIKit-component/9cceb502876d3cc16faebb4661956e101930bc2d/UIKit component handling/Support/apple.png -------------------------------------------------------------------------------- /UIKit component handling/Support/iOS_Security_Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calmone/iOS-UIKit-component/9cceb502876d3cc16faebb4661956e101930bc2d/UIKit component handling/Support/iOS_Security_Guide.pdf -------------------------------------------------------------------------------- /UIKit component handling/Support/vertical.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calmone/iOS-UIKit-component/9cceb502876d3cc16faebb4661956e101930bc2d/UIKit component handling/Support/vertical.jpeg -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling.xcodeproj/project.xcworkspace/xcuserdata/thyeon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calmone/iOS-UIKit-component/9cceb502876d3cc16faebb4661956e101930bc2d/UIKit component handling/UIKit component handling.xcodeproj/project.xcworkspace/xcuserdata/thyeon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling.xcodeproj/xcuserdata/thyeon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UIKit component handling.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/ComponentViewController/ButtonViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ButtonViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | self.view.backgroundColor = .white 18 | } 19 | 20 | override func didReceiveMemoryWarning() { 21 | super.didReceiveMemoryWarning() 22 | // Dispose of any resources that can be recreated. 23 | } 24 | 25 | 26 | /* 27 | // MARK: - Navigation 28 | 29 | // In a storyboard-based application, you will often want to do a little preparation before navigation 30 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 31 | // Get the new view controller using segue.destinationViewController. 32 | // Pass the selected object to the new view controller. 33 | } 34 | */ 35 | 36 | } 37 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/ComponentViewController/LabelViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LabelViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class LabelViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Do any additional setup after loading the view. 17 | self.view.backgroundColor = .white 18 | } 19 | 20 | override func didReceiveMemoryWarning() { 21 | super.didReceiveMemoryWarning() 22 | // Dispose of any resources that can be recreated. 23 | } 24 | 25 | 26 | /* 27 | // MARK: - Navigation 28 | 29 | // In a storyboard-based application, you will often want to do a little preparation before navigation 30 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 31 | // Get the new view controller using segue.destinationViewController. 32 | // Pass the selected object to the new view controller. 33 | } 34 | */ 35 | 36 | } 37 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/Support/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/Support/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/Support/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/Support/RootViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // UIKit component handling 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class RootViewController: UITableViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 24 | return tableView.frame.size.height / 9.5 25 | } 26 | 27 | override func numberOfSections(in tableView: UITableView) -> Int { 28 | return 1 29 | } 30 | 31 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 32 | return ComponentList.count 33 | } 34 | 35 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 36 | tableView.deselectRow(at: indexPath, animated: true) 37 | 38 | if let component = ComponentList.init(rawValue: indexPath.row) { 39 | self.navigationController?.pushViewController(component.getInfo().viewController, animated: true) 40 | } 41 | } 42 | 43 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 44 | let cell = tableView.dequeueReusableCell(withIdentifier: "uikitCell", for: indexPath) 45 | 46 | if let component = ComponentList.init(rawValue: indexPath.row) { 47 | cell.textLabel?.text = component.getInfo().name 48 | } 49 | 50 | return cell 51 | } 52 | 53 | } 54 | 55 | extension RootViewController { 56 | 57 | enum ComponentList: Int { 58 | case LABEL = 0 59 | case BUTTON 60 | 61 | func getInfo() -> ComponentInfo { 62 | switch self { 63 | case .LABEL: 64 | return ComponentInfo(name: "Lable", viewController: LabelViewController()) 65 | case .BUTTON: 66 | return ComponentInfo(name: "Button", viewController: ButtonViewController()) 67 | } 68 | } 69 | 70 | static var count: Int { return ComponentList.BUTTON.hashValue + 1} 71 | } 72 | 73 | struct ComponentInfo { 74 | var name: String 75 | var viewController: UIViewController 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handling/Support/UIKit_component_handling.xcdatamodeld/UIKit_component_handling.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handlingTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handlingTests/UIKit_component_handlingTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKit_component_handlingTests.swift 3 | // UIKit component handlingTests 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import UIKit_component_handling 11 | 12 | class UIKit_component_handlingTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handlingUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIKit component handling/UIKit component handlingUITests/UIKit_component_handlingUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKit_component_handlingUITests.swift 3 | // UIKit component handlingUITests 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class UIKit_component_handlingUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /UIKit component handlingTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIKit component handlingTests/UIKit_component_handlingTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKit_component_handlingTests.swift 3 | // UIKit component handlingTests 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import UIKit_component_handling 11 | 12 | class UIKit_component_handlingTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /UIKit component handlingUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UIKit component handlingUITests/UIKit_component_handlingUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIKit_component_handlingUITests.swift 3 | // UIKit component handlingUITests 4 | // 5 | // Created by Taehyeon Han on 2018. 7. 27.. 6 | // Copyright © 2018년 calmone. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class UIKit_component_handlingUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------