classViewController:UIViewController{
overridefuncviewDidLoad() {
super.viewDidLoad()
//button初始化
letaddButton=UIButton.init(type: .contactAdd)
addButton.frame=CGRect(x:10,y:150,width:100,height:30)
addButton.addTarget(self, action:#selector(tapped), for: .touchUpInside)
self.view.addSubview(addButton)
letcustomButton =UIButton(frame:CGRect(x:10,y:190,width:100,height:30))
customButton.setTitle("好长的字咋办呢你说咋办", for: .normal)
customButton.setTitleColor(UIColor.red, for: .normal)
customButton.titleLabel?.font=UIFont.systemFont(ofSize:12)
customButton.backgroundColor=UIColor.blue
customButton.addTarget(self, action:#selector(touchEd(_:)), for: .touchUpInside)
/*
byTruncatingTail:省略头部文字,省略部分用...代替
byTruncatingMiddle:省略中间部分文字,省略部分用...代替(默认)
byTruncatingTail:省略尾部文字,省略部分用...代替
byClipping:直接将多余的部分截断
byWordWrapping:自动换行(按词拆分)
byCharWrapping:自动换行(按字符拆分)
*/
customButton.titleLabel?.lineBreakMode= .byTruncatingTail
self.view.addSubview(customButton)
// Do any additional setup after loading the view, typically from a nib.
}
functapped(){
print("tapped")
}
functouchEd(_button:UIButton){
print(button.title(for: .normal) ??"111")
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
网友评论