美文网首页
初试Swift---UIButton

初试Swift---UIButton

作者: 磕瓜子的少年 | 来源:发表于2017-03-13 15:06 被阅读0次

    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.

    }

    }

    相关文章

      网友评论

          本文标题:初试Swift---UIButton

          本文链接:https://www.haomeiwen.com/subject/ggtvpttx.html