822
技術社區[雲棲]
Swift UI學習之基礎:UIButton,UILabel and UISlider
// // RootViewController.swift // UIDemos // // Created by sixiaobo on 14-6-10. // Copyright (c) 2014年 com.huangyibiao. All rights reserved. // import Foundation import UIKit class RootViewController : UIViewController, UIAlertViewDelegate { var _label: UILabel? // optional type, must type var func originX() -> CGFloat { let version: String = UIDevice.currentDevice().systemVersion return version >= "7.0" ? 64.0 : 0.0 } // // 重載需要使用關鍵字override override func viewDidLoad() { super.viewDidLoad() // 先調用父類的 // // @name create button println(self.originX()) let button = UIButton(frame: CGRectMake(30, self.originX() + 30, 100, 30)) button.setTitle("button", forState:UIControlState.Normal) button.backgroundColor = UIColor.blackColor() button.setTitleColor(UIColor.whiteColor(), forState:.Normal) // add an action button.addTarget(self, action: "onButtonClick:", forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button) // @} end create button // // @name create label _label = UILabel(frame: CGRectMake(30, self.originX() + 70, 100, 60)) _label!.text = "label" _label!.backgroundColor = UIColor.clearColor() _label!.textColor = UIColor.redColor() // use NSTextAlignment _label!.textAlignment = NSTextAlignment.Center self.view.addSubview(_label!) // @} end create label // // @name create UISlider let slider = UISlider(frame: CGRectMake(30, self.originX() + 130, 60, 30)) slider.addTarget(self, action: "clickSlider:", forControlEvents: .ValueChanged) slider.minimumValue = 17.0 slider.maximumValue = 36.0 self.view.addSubview(slider) // @} end create UISlider } func onButtonClick(sender: UIButton!) { // UIAlertController.showAlert(self, title: "title", message: "message") // UIAlertController.showAlert(self, title: "title", message: "message", cancelButtonTitle: "cancel", okButtonTitle: "ok") UIAlertController.showAlert(self, title: "title", message: "message", cancelButtonTitle: "cancel", okButtonTitle: "ok", okHandler: { (UIAlertAction) in println("no nothing") }) } func alertView(alertView: UIAlertView!, clickedButtonAtIndex buttonIndex: Int) { println("clicked button at index: \(buttonIndex)") } func clickSlider(sender: UISlider!) { _label!.font = UIFont.systemFontOfSize(sender.value) } }
最後更新:2017-04-03 07:56:58
上一篇:
git上上傳項目
下一篇:
Swift 學習之二十:類型強轉(+、-、*、/)
馬雲自稱麥霸!雲棲音樂節連唱四首 網友:實力派!
謹慎看待史玉柱
黑莓ECLIPSE3.5開發環境不識別資源文件導致編譯不通過解決方案附文件(係統語言問題)
Fragment與Fragment之間的回調
做一個有思想的技術人
【Linux FTP】(2)FTP服務器虛擬賬戶登錄創建過程
sendBroadcastAsUser——Calling a method in the system process without a qualified user
c++編譯時如何把private屬性變成public?
Oracle中的Exists、In、ANY、ALL
一套Vue的單頁模板:N3-admin