博客> Swift day1 button label
Swift day1 button label
2019-05-20 12:29 评论:0 阅读:844 boluo20141010
ios swift2.2

从OC到Swift 慢慢来吧,每天学习一点新知识

override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.creatUI() }

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("Swift Day1")
}
收藏
0
sina weixin mail 回到顶部