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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值