iOS 基本UI控件

1.UIlabel

 var label = UILabel(frame: CGRectMake(100, 100, 100, 50))//初始化uilabel
        label.text="this is a label"
        label.textColor = UIColor.redColor()
        label.textAlignment = NSTextAlignment.Right //對齊方式,這裏貌似沒起作用,可能初始化的時候定死了?
        label.backgroundColor = UIColor.grayColor()
        label.font = UIFont(name: "Zapfino", size: 20)
        label.numberOfLines = 2 // 最多顯示幾行
        label.lineBreakMode = NSLineBreakMode.ByTruncatingTail //文字的省略方式,ByTruncatingTail表示尾部顯示省略號

2.UIButton

//        創建button,常用System ,如果要定製,則用.Custom,如果要創建自定義的button 則可以簡化爲var button = UIButton (CGRectMake(1,2,3,4);
        var button : UIButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton

        button.frame = CGRectMake(100, 100, 100, 50)
        //button的按鈕和狀態
        button.setTitle("普通狀態", forState: UIControlState.Normal)
        button.setTitle("觸摸狀態", forState: UIControlState.Highlighted)
        button.setTitle("禁用狀態", forState: UIControlState.Disabled)

        // button不同狀態下的字體顏色,和上面類似 
        button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        button.setTitleColor(UIColor.redColor(), forState: UIControlState.Highlighted)
        button.setTitleColor(UIColor.blueColor(), forState: UIControlState.Disabled)
發佈了28 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章