Swift - UIView,UILabel,UIButton,UIImageView
来源:互联网 发布:cisco查看端口流量 编辑:程序博客网 时间:2024/05/16 08:46
学习Swift没少查资料,但是发现网上都是对一些基础语法的介绍,还有些看不明白的,博主觉得么,没必要看的那么详细,等使用中自然就会懂了。但是使用的时候,我们最常用的UIView,UILabel,UIButton,UIImageView却没有说怎么用,今天博主就来介绍这些我们常用的控件怎么用,有了这些控件的使用方法,普通界面我们已经能够随手搭出来了:
代码统一放,博主简单写了个工程
import UIKitclass ViewController: UIViewController { var myView = UIView() var myLabel = UILabel() var myButton = UIButton() var myImageView = UIImageView() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.toCreatAUIView() self.toCreatAUILabel() self.toCreatAUIButton() self.creatAUIImageView() } /** toCreatAUIView */ func toCreatAUIView () { myView.frame = CGRectMake(0, 0, 320, 568) myView.backgroundColor = UIColor.blueColor() self.view.addSubview(myView) } /** toCreatAUILabel */ func toCreatAUILabel() { myLabel.frame=CGRectMake(10, 20, 300, 60); myLabel.text = "This is a UILabel!" myLabel.backgroundColor = UIColor.redColor() myLabel.textColor = UIColor.whiteColor() myLabel.textAlignment = NSTextAlignment.Center myLabel.layer.borderWidth = 1 myView.addSubview(myLabel) } /** toCreatAUIButton */ func toCreatAUIButton() { myButton.frame = CGRectMake(10, 100, 300, 60); myButton.setTitle("This is a UIButton", forState: .Normal) myButton.setTitleColor(UIColor.whiteColor(), forState: .Normal) myButton.setImage(UIImage.init(named: ""), forState: .Normal) myButton.layer.borderWidth = 1 myButton.layer.cornerRadius = 5 myButton.layer.borderColor = UIColor.blackColor().CGColor myButton.addTarget(self, action: #selector(self.myButtonAction(_:)), forControlEvents: .TouchUpInside) myView.addSubview(myButton) } /** myButtonAction - parameter btn: An AlertView */ func myButtonAction(btn:UIButton) { let myAlertView = UIAlertView() myAlertView.title = "alertView" myAlertView.message = "This is a UIAlertView" myAlertView.addButtonWithTitle("Cancel") myAlertView.addButtonWithTitle("Ok") myAlertView.cancelButtonIndex = 0 myAlertView.show() } /** creatAUIImageView */ func creatAUIImageView() { myImageView.frame = CGRectMake(10, 200, 300, 300); myImageView.image = UIImage.init(named: "fire.jpg") myImageView.userInteractionEnabled = true myView.addSubview(myImageView) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}
打完收工,想学到更多的Swift相关的知识,欢迎关注,博主比较懒,重实用,比较难理解的概念暂时都会放放,先达到能做项目的程度。
0 0
- Swift - UIView,UILabel,UIButton,UIImageView
- UIView UILabel UITextField UIButton UIImageView 常用属性
- iOS基本常用控件总结(UIView,UILabel,UIButton,UIImageView)
- UIButton UIImageVIew UIView UILabel 等控件设置一个圆角
- UIButton,UIImageView,UILabel,UITextField
- UILabel,UITextField,UIButton,UIimageView
- swift基础学习UI(01)[UIView、UILabel、UIButton]
- UIView UILabel UITextField UIButton
- UIView,UILabel,UIButton,
- UILabel、UITextField、UIButton、UIImageView控件
- iOS UILabel UIButton UIImageView使用方法
- iOS个人整理06-第一周小结,常用控件UIView,UILabel,UIImageView,UIButton,UITextField
- iOS基础——UI控件之UIView、UITextField、UILabel、UIColor、UIButton、UIImageView
- UIView UIButton UIImageView 添加事件
- UIView,UILabel,UITextField,UIButton使用方法
- UIView UILabel UIButton知识整理
- Swift - 如何让UIView,UILabel和UIImageView之间类型互相转化
- iOSDay21之UILabel, UITextField, UIButton, UIImageView
- VideoJS live RTMP stream, player and video size issue
- 查看AppStore中App的Appid
- Bash中的任务(job)管理
- 单元测试设计原则
- iOS MVVM架构的介绍(内含Demo)
- Swift - UIView,UILabel,UIButton,UIImageView
- Disruptor编程指南
- 谷歌发布Android Awareness API,提升应用智能化
- 『python学习』正则表达式学习
- Django Admin管理 fields和list_display的区别
- Web应用跨域访问解决方案汇总
- JDK JRE JVM的区别:
- MFC界面库BCGControlBar v25.0新功能详解二:网格和报表控件
- spring boot 学习笔记(009)application.yml