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

  • 相关阅读:
    冲突域和广播域的区分
    internet 的一词多义
    大神洗礼第四讲——函数相关及编程技巧
    旋转字符串算法由浅入深
    一个交换程序的通用版本
    想起一些事情,都很遥远
    [转载]创业感想
    [转载]javascript小技巧
    [转载]在Asp.Net 2.0中应用DataFormatString
    [转载]C#的String.Format格式化举例
  • 原文地址:https://www.cnblogs.com/laolitou-ping/p/7691126.html
Copyright © 2011-2022 走看看