Swift UIButton UIButtonType

来源:互联网 发布:腾讯数据库有多大 编辑:程序博客网 时间:2024/05/20 01:47

UIButton 有一个枚举

UIButtonType

专门用来指定button的类型

这里我们尝试一下接种类型看看效果、


        //按钮的几种类型                //系统默认button        let btn1=UIButton.buttonWithType(UIButtonType.System) as! UIButton        btn1.frame=CGRectMake(20, 50, 320, 36);        btn1.setTitle("SystemButton", forState: UIControlState.Normal);        self.view.addSubview(btn1);                //所有属性需要自定义,否则字体颜色为白色        let btn2=UIButton.buttonWithType(UIButtonType.Custom) as! UIButton        btn2.frame=CGRectMake(20, 100, 320, 36);        btn2.setTitle("CustomButton", forState: UIControlState.Normal);        btn2 .setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)        self.view.addSubview(btn2);                //以下为几种带图标的button        let btn3=UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton        btn3.frame=CGRectMake(20, 150, 320, 36);        btn3.setTitle("DetailDisclosureButton", forState: UIControlState.Normal);        self.view.addSubview(btn3);                let btn4=UIButton.buttonWithType(UIButtonType.InfoLight) as! UIButton        btn4.frame=CGRectMake(20, 200, 320, 36);        btn4.setTitle("InfoLightButton", forState: UIControlState.Normal);        self.view.addSubview(btn4);                let btn5=UIButton.buttonWithType(UIButtonType.InfoDark) as! UIButton        btn5.frame=CGRectMake(20, 250, 320, 36);        btn5.setTitle("InfoDarkButton", forState: UIControlState.Normal);        self.view.addSubview(btn5);                let btn6=UIButton.buttonWithType(UIButtonType.ContactAdd) as! UIButton        btn6.frame=CGRectMake(20, 300, 320, 36);        btn6.setTitle("ContactAddButton", forState: UIControlState.Normal);        self.view.addSubview(btn6);        




需要注意的是 按照以上几种方式创建的button将不能相互转换为其他类型了


苹果开发群 :414319235  欢迎加入  欢迎讨论问题



0 0