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)

你可能感兴趣的:(ios)