博客> Swift button label
Swift button label
2017-11-22 15:58 评论:0 阅读:348 boluo20141010
ios 按钮 swift(2.2) 标签

func creatUI() { let button = UIButton(type:.Custom) button.frame = CGRectMake(0,0, 100, 100) button.center = self.view.center button.backgroundColor = UIColor.blackColor() let title = "Hello Swift" button.setTitle(title, forState: .Normal) button.setTitleColor(UIColor.whiteColor(), forState: .Normal) button.addTarget(self, action: "click", forControlEvents: .TouchUpInside)

    self.view.addSubview(button)

    let rectRect:CGRect = CGRectMake((self.view.frame.size.width-100)/2,CGRectGetMaxY(button.frame)+20,100,30)
    let label:UILabel = UILabel(frame:rectRect)
    label.text = "这是一个label"
    label.backgroundColor = UIColor.grayColor()
    label.textAlignment = NSTextAlignment.Center
    label.adjustsFontSizeToFitWidth = true
  //  label.font = UIFont.boldSystemFontOfSize(14)
   // label.font = UIFont.systemFontOfSize(14)
    label.textColor = UIColor.redColor()
    self.view.addSubview(label)

}
func click()
{
    print("第一个点击事件")
}
收藏
0
sina weixin mail 回到顶部