• UIButton Swift


    1,按钮的创建
    (1)按钮有下面四种类型:

    UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
    UIButtonType.DetailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
    UIButtonType.System:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
    UIButtonType.Custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
    UIButtonType.InfoDark:为感叹号“!”圆形按钮
    UIButtonType.InfoLight:为感叹号“!”圆形按钮

     let btn=UIButton(type: .ContactAdd)

     

    (2)对于Custom定制类型按钮,代码可简化为:

       let button=UIButton(frame: CGRect(x: 0, y: 0, 100, height: 100))

            button.backgroundColor=UIColor.purpleColor()

           // button.frame=CGRectMake(0, 0, 100, 100)

            button.titleLabel!.font=UIFont.systemFontOfSize(20)//文字的大小

            button.setTitle("Swift", forState:UIControlState.Normal)

            button.setTitle("Button", forState: UIControlState.Highlighted)

        

            button.setTitleColor(.redColor(), forState: UIControlState.Normal)//普通状态下文字的颜色

            button.setTitleColor(UIColor.yellowColor(), forState: UIControlState.Highlighted)

            button.setTitleShadowColor(UIColor.whiteColor(), forState: UIControlState.Normal)//普通状态下文字阴影的颜色

            button.setTitleShadowColor(UIColor.blackColor(), forState: UIControlState.Highlighted)

            button.setImage(UIImage(named: "Icon-72"), forState: UIControlState.Normal)//设置图标

            button.adjustsImageWhenHighlighted=false//使触摸模式下按钮也不会变暗

            

            button.setBackgroundImage(UIImage(named: "1.jpg"), forState: UIControlState.Normal)//背景图片

            button.addTarget(self, action: Selector("clicekdBtn:"), forControlEvents: .TouchUpInside)

            self.view.addSubview(button)

        }

        func clicekdBtn(button:UIButton){

        print(button.titleForState(UIControlState.Normal))

        }

  • 相关阅读:
    NetCore基于Consul+Ocelot+Docker+Jenkin搭建微服务架构
    Linux文档整理之【Jenkins+Docker自动化部署.Net Core】
    分布式事务
    redis
    pandas读取Excel
    centos7上用docker搭建简单的前后端分离项目
    CENTOS 设置swap 并让系统使用它
    MikroTik RouterOS安装chr授权到阿里云虚拟机(转)
    IDEA使用External Tools配置来查看javap反编译字节码
    【k8s】metrics-server
  • 原文地址:https://www.cnblogs.com/woaixixi/p/4995370.html
Copyright © 2020-2023  润新知