swift基础控件的创建

/* let apples = 3 let orange = 5 let L = 1.1 let appleSummary = "I have \(apples) apples" let fruitSummary = "I have \(apples + orange) pieces of fruit." let isay = "I love \(L) you " print(isay) let expliciFloat: Float = 4 // print(fruitSummary) print(expliciFloat) let label = "label" let width = 94 let widthlabel = label + String(width) print(widthlabel) */

        /*初始化一个数组有值数组*/
        var shoppingList = ["catfish","water","tulips","agg","water"]

        var dic = [
            "A":"a","B":"b",]
        shoppingList[1] = "aaaaaa"
//        print(shoppingList[0])

        /*初始化一个空的数组和字典*/
//        let emptyArray = String["",""]()
         let emptyDictionary = Dictionary<String,Float >()
        print(emptyDictionary)

        let textLabel = UILabel (frame:CGRectMake(self.view.frame.size.width/8,20,self.view.frame.size.width*3/4,100))


//        给label 设值
        textLabel.text = "现在我们来开始学习如何创建我们的第一个swift控件吧 -UILabel"
//        设置是否认换行
        textLabel.numberOfLines = 0
//        设置label的背景颜色
        var whitColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:1.0)
        textLabel.backgroundColor = whitColor
        self.view.addSubview(textLabel)



        //view
        let view  = UIView (frame: CGRectMake(100,100,100))
        view.backgroundColor = UIColor.blueColor()
        self.view.addSubview(view)



        //textfield
        let textfield = UITextField(frame: CGRectMake(20,200,50))
        textfield.text = "哈哈"
        textfield.textColor = UIColor.redColor()
        self.view.addSubview(textfield)

        //button
        let button = UIButton(frame: CGRectMake( 20,250,150,30))
        button.backgroundColor = UIColor.purpleColor()
        button.titleLabel?.text = "1111"
        button.addTarget(self,action:Selector("buttonClick:"),forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)

        //imageview
        let imageview = UIImageView (frame: CGRectMake(20,300,300))
        imageview.image = UIImage(named: "UnkNown")
        self.view.addSubview(imageview)

    }

    //按钮监听
    func buttonClick(btn:UIButton){
            print(btn.titleLabel?.text)
        }
![如下图](http://img.blog.csdn.net/20150605234753408)

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...