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:省略中間部分文字,省略部分用...代替(默認(rèn))
byTruncatingTail:省略尾部文字鲸湃,省略部分用...代替
byClipping:直接將多余的部分截?cái)?/p>
byWordWrapping:自動(dòng)換行(按詞拆分)
byCharWrapping:自動(dòng)換行(按字符拆分)
*/
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.
}
}