zoukankan      html  css  js  c++  java
  • Swift UIView常用方法

    import UIKit

    class ViewController: UIViewController {

        override func viewDidLoad() {
            super.viewDidLoad()
           
        
            let button = UIButton(type:.system);
            button.frame = CGRect.init(x:100,y:150,160,height:30);
            button.setTitle("changColor", for: .normal);
            button.backgroundColor = UIColor.brown;
            button.titleLabel?.font = UIFont.systemFont(ofSize: 17);
            button.tintColor = UIColor.cyan;
            button.addTarget(self, action: #selector(buttonDidClick), for: .touchUpInside);
            self.view.addSubview(button);
        
            let smallView = UIView();
            smallView.frame = CGRect.init(x: 50, y: 50, 100, height: 100);
            smallView.backgroundColor = UIColor.darkGray;
            smallView.tag = 100;
            self.view.addSubview(smallView);
            
        }
        func buttonDidClick() {
            print("按钮被点击了");
            let changView = self.view.viewWithTag(100);
            
            changView?.backgroundColor = UIColor.init(colorLiteralRed: Float(CGFloat(arc4random()%256)/255.0), green: Float(CGFloat(arc4random()%256)/255.0), blue: Float(CGFloat(arc4random()%256)/255.0), alpha: 1.0)
            
        }

    }
    详细代码查看:https://github.com/xiaolitou-ping/Swift-All

  • 相关阅读:
    Yet Another Monster Killing Problem
    Element Extermination
    最短路径
    Secret Passwords
    New Year Parties
    Water The Garden
    Zero Quantity Maximization
    Anya and Cubes
    代码规范&《数学之美》读后感
    带负边权的最短路径(有向图)——Bellman-Ford算法
  • 原文地址:https://www.cnblogs.com/laolitou-ping/p/7691126.html
Copyright © 2011-2022 走看看