#16 心理測驗或問卷 App

程式碼AnswerViewController.swift :

import UIKitclass AnswerViewController: UIViewController {@IBOutlet weak var AnswerLabel: UILabel!@IBOutlet weak var titAnswerLabel: UILabel!var totals = 0var titAnswer = [“【低於21分:內向的悲觀者】”,”【21分到30分:缺乏信心的挑剔者】”,”【31分到40分:以牙還牙的自我保護者】”,”【41分到50分:平衡的中道】”,”【51分 到60分:吸引人的冒險家】”,”【60分以上:傲慢的孤獨者】”]var answer = [“人們認 為你是一個害羞的、神經質的、優柔寡斷的,是須人照顧、永遠要別人為你做決定、不想與任何事或任何人有關。他們認為你是一個 杞人憂天者,一個永遠看到不存在的問題的人。有些人 認為你令人 乏味,只有那些深知你的人知道你不是這樣的人.”,”你的朋友認為你勤 勉刻苦、很挑剔。他們認為你是一個謹慎的、十分小心的人,一個 緩慢而穩定辛勤工作的人。如果你做任何衝動的事或無準備的事,你會令他們大吃一驚。他們認為你會從各個角度仔細地檢查一切之後仍經常決定不做。他們認為對你的這種反應一部分是因為你的小心的天性所引起的。”,”別人認為你是明智、謹慎、注重實效的人。也認為你是 一個伶俐、有天賦有才幹且謙虛的人。你不會很快、很容易和人成 為朋友,但是是一個對朋友非常忠誠的人,同時要求朋友對你也有 忠誠的回報。那些真正有機會瞭解你的人會知道要動搖你對朋友的 信任是很難的,但相等的,一旦這信任被破壞,會使你很難熬過。”,”別人認為你是一個新鮮的、有活力的、有魅力的、好玩的、講究實際的、而永遠有趣的人; 一個經常是群眾注意力的焦點,但是你是一個足夠平衡的人,不至於因此而昏了頭。他們也認為你親切、和藹、體貼、能諒解人;一個永遠會使人高興起來並會幫助別人的人。”,”別人認為你是一個令人興奮的、高度活 潑的、相當易衝動的個性;你是一個天生的領袖、一個做決定會很 快的人,雖然你的決定不總是對的。他們認為你是大膽的和冒險的 ,會願意試做任何事至少一次;是一個願意嘗試機會而欣賞冒險的 人。因為你散發的刺激,他們喜歡跟你在一起。”,”別人認為對你必須「小心 處理」。在別人的眼中,你是自負的、自我中心的、是個極端的傢伙”]override func viewDidLoad() {if totals < 21 {AnswerLabel.text = answer[0]titAnswerLabel.text = titAnswer[0]}else if totals >= 21 || totals <= 30 {AnswerLabel.text = answer[1]titAnswerLabel.text = titAnswer[1]}else if totals >= 31 || totals <= 40 {AnswerLabel.text = answer[2]titAnswerLabel.text = titAnswer[2]}else if totals >= 41 || totals <= 50 {AnswerLabel.text = answer[3]titAnswerLabel.text = titAnswer[3]}else if totals >= 51 || totals <= 60 {AnswerLabel.text = answer[4]titAnswerLabel.text = titAnswer[4]}else {AnswerLabel.text = answer[5]titAnswerLabel.text = titAnswer[5]}super.viewDidLoad()// Do any additional setup after loading the view.}

程式碼:TopicViewController.swift

import UIKitclass TopicViewController: UIViewController {@IBOutlet weak var questionLabel: UILabel!@IBOutlet weak var AoptionButton: UIButton!@IBOutlet weak var BoptionButton: UIButton!@IBOutlet weak var CoptionButton: UIButton!@IBOutlet weak var DoptionButton: UIButton!@IBOutlet weak var EoptionButton: UIButton!@IBOutlet weak var FoptionButton: UIButton!@IBOutlet weak var GoptionButton: UIButton!var index = 0var aButton = [2,6,4,4,6,6,6,6,7,4]var bButton = [4,4,2,6,4,4,2,7,6,2]var cButton = [6,7,5,2,3,2,4,5,4,3]var dButton = [0,2,7,1,5,0,0,4,2,5]var eButton = [0,1,6,0,0,0,0,3,1,6]var fButton = [0,0,0,0,0,0,0,2,0,1]var gButton = [0,0,0,0,0,0,0,1,0,0]var aTotal = 0var bTotal = 0var cTotal = 0var dTotal = 0var eTotal = 0var fTotal = 0var gTotal = 0var total = 0var a = 0var b = 0var c = 0var d = 0var e = 0var f = 0var g = 0var questions : [Topic] = [Topic(question:”1.你何時感覺最好?”, option:[“a.早晨”,”b.下午及傍晚”,”c.夜”,””,””,””,””]),Topic(question:”2.你走路時是……?”, option:[“a.大步的快走”,”b.小步的快走”,”c.不快,仰著頭面對著世界”,”d.不快,低著頭”,”e.很慢”,””,””]),Topic(question:”3.和人說話時,你……?”, option:[“a.手臂交疊的站著”,”b.雙手緊握著”,”c.一隻手或兩手放在臀部”,”d.碰著或推著與你說話的人”,”e.玩著你的耳朵、摸著你的下巴、或用手整理頭髮”,””,””]),Topic(question:”4.坐著休息時,你的……?”, option:[“a.兩膝蓋併攏”,”b.兩腿交叉”,”c.兩腿伸直”,”d.一腿卷在身下”,””,””,””]),Topic(question:”5.碰到你感到發笑的事時,你的反應是……?”, option:[“a.一個欣賞的大笑”,”b.笑著,但不大聲”,”c.輕聲的咯咯地笑”,”d.羞怯的微笑”,””,””,””]),Topic(question:”6.當你去一個派對或社交場合時,你……?”, option:[“a.很大聲地入場以引起注意”,”b.安靜地入場,找你認識的人”,”c.非常安靜地入場,儘量保持不被注意”,””,””,””,””]),Topic(question:”7.當你非常專心工作時,有人打斷你,你會……?”, option:[“a.歡迎他”,”b.感到非常惱怒”,”c.在上兩極端之間”,””,””,””,””]),Topic(question:”8.下列顏色中,你最喜歡哪一顏色?”, option:[“a.紅或橘色”,”b.黑色”,”c.黃或淺藍色”,”d.綠色”,”e.深藍或紫色”,”f.白色”,”g.棕或灰色”]),Topic(question:”9.臨入睡的前幾分鐘,你在床上的姿勢是……?”, option:[“a.仰躺,伸直”,”b.俯躺,伸直”,”c.側躺 ,微卷”,”d.頭睡在一手臂上”,”e.被蓋過頭”,””,””]),Topic(question:”10.你經常夢到你在……?”, option:[“a.落下”,”b.打架或掙扎”,”c.找東西或人”,”d.飛或漂浮”,”e.你平常不做夢”,”f.你的夢都是愉快的”,””])]@IBAction func pressed(_ sender: UIButton) {switch sender.tag {case 1 :self.a = self.aButton[self.index]self.aTotal = self.aTotal + self.acase 2 :self.b = self.bButton[self.index]self.bTotal = self.bTotal + self.bcase 3 :self.c = self.cButton[self.index]self.cTotal = self.cTotal + self.ccase 4 :self.d = self.dButton[self.index]self.dTotal = self.dTotal + self.dcase 5 :self.e = self.eButton[self.index]self.eTotal = self.eTotal + self.ecase 6 :self.f = self.fButton[self.index]self.fTotal = self.fTotal + self.fcase 7 :self.g = self.gButton[self.index]self.gTotal = self.gTotal + self.gdefault :break}self.total = self.aTotal + self.bTotal + self.cTotal + self.dTotal + self.eTotal + self.fTotal + self.gTotalself.index += 1if index <= 9 {newRound()}else {self.performSegue(withIdentifier: “Segue”, sender: nil)}}func newRound () {self.questionLabel.text = self.questions[self.index].questionself.AoptionButton.setTitle(self.questions[self.index].option[0], for: .normal)self.BoptionButton.setTitle(self.questions[self.index].option[1], for: .normal)self.CoptionButton.setTitle(self.questions[self.index].option[2], for: .normal)self.DoptionButton.setTitle(self.questions[self.index].option[3], for: .normal)self.EoptionButton.setTitle(self.questions[self.index].option[4], for: .normal)self.FoptionButton.setTitle(self.questions[self.index].option[5], for: .normal)self.GoptionButton.setTitle(self.questions[self.index].option[6], for: .normal)}override func viewDidLoad() {newRound()super.viewDidLoad()// Do any additional setup after loading the view.}// MARK: — Navigation// In a storyboard-based application, you will often want to do a little preparation before navigationoverride func prepare(for segue: UIStoryboardSegue, sender: Any?) {let controller = segue.destination as? AnswerViewControllercontroller?.totals = self.total// Get the new view controller using segue.destination.// Pass the selected object to the new view controller.}}

程式碼:Question.swift

import Foundationstruct Topic {var question : Stringvar option : [String]}

--

--