This file contains hidden or 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
class UITextViewPadding : UITextView { | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 8, right: 4) | |
} | |
} |
This file contains hidden or 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 Foundation | |
class UITextFieldPadding : UITextField { | |
let padding = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
This file contains hidden or 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 Foundation | |
import UIKit | |
@IBDesignable | |
class DesignableView: UIView { | |
} | |
@IBDesignable | |
class DesignableButton: UIButton { | |
} |
This file contains hidden or 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
// Temporary view | |
self.question_View.addSubview(temp_View) | |
temp_View.backgroundColor = UIColor.white | |
temp_View.snp.makeConstraints { (make) in | |
make.edges.equalTo(question_View) | |
} | |
// Topic Label | |
temp_View.addSubview(topic_Label) | |
topic_Label.text = question.title |
This file contains hidden or 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 viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
if (self.isMovingFromParentViewController) { | |
UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation") | |
} | |
} |
This file contains hidden or 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 application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { | |
if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) { | |
if (rootViewController.responds(to: Selector(("canRotate")))) { | |
// Unlock landscape view orientations for this view controller | |
return .allButUpsideDown; | |
} | |
} | |
// Only allow portrait (standard behaviour) | |
return .portrait; |
This file contains hidden or 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
//c. 處理TableviewCell的DishesTableViewCell。 | |
class DishesTableViewCell: UITableViewCell { | |
@IBOutlet weak var nameMeal: UILabel! | |
@IBOutlet weak var timeMeal: UILabel! | |
@IBOutlet weak var imageMeal: UIImageView! | |
This file contains hidden or 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
//b. 創造一個Swift檔(Meals),裝載NSObject,這裡的名稱都要跟Firebase裡面的Child名稱一模一樣。 | |
class Meals: NSObject{ | |
var FoodName: String? | |
var cookTime: String? | |
var cookPic: String? | |
var cookhow: String? |
This file contains hidden or 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
// a.原本的ViewController(MainTableViewController) 部份截取,詳細請至github下載完整專案 | |
func fetchMealsList(){ //將這個function放至viewDidLoad中 | |
//之前提到的.childAdded是專門處理List | |
refHandle = databaseRef.child("Meal").observe(.childAdded, with: { (snapshot) in | |
if let dictionary = snapshot.value as? [String : AnyObject]{ | |
let mealDetail = Meals() | |
This file contains hidden or 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
//確定按鈕 Confirm (儲存資料並到Tableview頁面) | |
@IBAction func confirm(_ sender: Any) { | |
// 這些空格不能是空的 | |
if cookName.text != "" && foodName.text != "" && cookTime.text != "" && cookHow.text != ""{ | |
// Meal > uniqueString > NSObject > value | |
//之後在MainTableViewController會看到 *.childAdded | |
// 通常為了處理 list 的資料,像是許多聊天室的練習就會用到 childAdded ,因為聊天內容都是非常多句,也可以稱為一個list | |
NewerOlder