zoukankan      html  css  js  c++  java
  • Swift_UIButton

    1.初始化

            /**
             UIButtonType.system:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
             UIButtonType.contactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.detailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.infoDark:为感叹号“!”圆形按钮
             UIButtonType.infoLight:为感叹号“!”圆形按钮
             (注意:自ios7起,infoDark、infoLight、detailDisclosure效果都是一样的)
             */
            let buttonOne = UIButton.init(type: UIButtonType.custom)

    2. 设置

            /**
             normal
             highlighted
             disabled
             selected
             */
            buttonOne.setTitle("这个是一个button", for: UIControlState.normal)
            buttonOne.setImage(UIImage.init(named: "1.jpg"), for: UIControlState.normal)
            
            // 设置背景颜色
            buttonOne.setBackgroundImage(UIImage.init(named: "2"), for: UIControlState.normal)
            
            // 点击事件
            buttonOne.addTarget(self, action: #selector(buttonOneClicked), for: UIControlEvents.touchUpInside)

    3.代码

    import UIKit
    
    let kScreenWidth = UIScreen.main.bounds.size.width
    
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            
            self.addButtonOne()
        }
        
        
        func addButtonOne() {
            
            self.view.addSubview(buttonOne)
        }
        
        func buttonOneClicked()  {
            print("点击了")
        }
        
        // 懒加载一个UIButton
        lazy var buttonOne: UIButton = {
    
            /**
             UIButtonType.system:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
             UIButtonType.contactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.detailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
             UIButtonType.infoDark:为感叹号“!”圆形按钮
             UIButtonType.infoLight:为感叹号“!”圆形按钮
             (注意:自ios7起,infoDark、infoLight、detailDisclosure效果都是一样的)
             */
            let buttonOne = UIButton.init(type: UIButtonType.custom)
            
            
            buttonOne.frame = CGRect.init(x: 10, y: 100,  kScreenWidth - 20, height: 40)
            buttonOne.backgroundColor = UIColor.red
            
            
            /**
             normal
             highlighted
             disabled
             selected
             */
            buttonOne.setTitle("这个是一个button", for: UIControlState.normal)
            buttonOne.setImage(UIImage.init(named: "1.jpg"), for: UIControlState.normal)
            
            // 设置背景颜色
            buttonOne.setBackgroundImage(UIImage.init(named: "2"), for: UIControlState.normal)
            
            // 点击事件
            buttonOne.addTarget(self, action: #selector(buttonOneClicked), for: UIControlEvents.touchUpInside)
            
            return buttonOne
        }()
    }
  • 相关阅读:
    sqlserver跨数据库查询数据
    sqlserver调用钉钉方法
    SQL Server判断对象是否存在
    再学一次C#(基本类型篇)
    .net core部署到centos官方文档的一点小问题
    C#字符串和byte之间的互相转化(转载出自:https://www.cnblogs.com/liangxiaoking/p/5958456.html)
    30分钟通过Kong实现.NET网关
    Envoy实现.NET架构的网关(五)集成Redis实现限流
    Envoy实现.NET架构的网关(四)集成IdentityServer4实现OAuth2认证
    Envoy实现.NET架构的网关(三)代理GRPC
  • 原文地址:https://www.cnblogs.com/mancong/p/6266603.html
Copyright © 2011-2022 走看看