This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SwifterSwift | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
// 日期處理 | |
var date: Date = Date() | |
print("isInToday: \(date.isInToday)") // 判斷日期是否為今天 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
var mainVC: ViewController? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// 設定 Controller 的入口 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - LifeCycle | |
// --------------------------------------------------------------------- | |
override func viewDidLoad() { | |
let w: CGFloat = self.view.frame.size.width | |
let h: CGFloat = self.view.frame.size.height - 20 | |
// 產生UIScrollView | |
self.scrollView = UIScrollView() | |
self.scrollView!.frame = CGRect(x: 0, y: 0, width: w, height: h) | |
self.scrollView!.contentSize = CGSize(width: w * CGFloat(self.movieImage.count), height: h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 自動切頁 | |
func onAutoChangePageAction() { | |
self.scrollView.setContentOffset(CGPoint(x: self.scrollView.frame.size.width * CGFloat(self.currenPageNumber), y: 0), animated: true) | |
self.pageControl.currentPage = self.currenPageNumber | |
self.currenPageNumber += 1 | |
if self.currenPageNumber == 3 { | |
self.currenPageNumber = 0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 滑動圖片切頁所會觸發的事件 | |
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | |
// 利用scrollView的容器內X座標算出UIPageController要顯示第幾頁 | |
let currentPage: CGFloat = scrollView.contentOffset.x / self.view.frame.size.width | |
self.pageControl.currentPage = Int(currentPage) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
// JSON格式資料網址 | |
let url: URL = URL(string: "http://data.taipei/opendata/datalist/apiAccess?scope=resourceAquire&rid=201d8ae8-dffc-4d17-ae1f-e58d8a95b162")! | |
// 建立session設定 | |
let sessionWithConfigure = URLSessionConfiguration.default | |
// 設定委任對象為自己 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 下載完成觸發的Delegate | |
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) { | |
do { | |
// 將取得的資料轉型為JSON格式 | |
let dataDic = try JSONSerialization.jsonObject(with: NSData(contentsOf: location as URL)! as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String:[String:AnyObject]] | |
// 將Dictionary存放在陣列裡 | |
self.dataArray = dataDic["result"]!["results"] as! [AnyObject] | |
// 印出取回的資料 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
self.view.backgroundColor = UIColor.white | |
// 生成圖片顯示框 | |
self.imageView = UIImageView() | |
self.imageView.frame = CGRect(x: self.view.frame.size.width / 4 / 2, y: 64, width: self.view.frame.size.width / 4 * 3, height: self.view.frame.size.height / 4 * 2) | |
self.imageView.image = UIImage(named: "profile") | |
// 生成相機按鈕 | |
let cameraBtn: UIButton = UIButton() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 開啟相機或相簿 | |
/// | |
/// - Parameter kind: 1=相機,2=相簿 | |
func callGetPhoneWithKind(_ kind: Int) { | |
let picker: UIImagePickerController = UIImagePickerController() | |
switch kind { | |
case 1: | |
// 開啟相機 | |
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { | |
picker.sourceType = UIImagePickerControllerSourceType.camera |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 取得選取後的照片 | |
/// | |
/// - Parameters: | |
/// - picker: pivker | |
/// - info: info | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { | |
picker.dismiss(animated: true, completion: nil) // 關掉 | |
self.imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage // 從Dictionary取出原始圖檔 | |
} | |
OlderNewer