Swift UIImageView經常使用方法

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        let image = UIImage.init(named: "111.png");
        
        let imageView = UIImageView();
        imageView.frame = CGRect.init(x: 100, y: 10, width: 200, height: 200);
        imageView.image = image;
        self.view.addSubview(imageView);
        //圓角
        imageView.layer.masksToBounds = true;
        imageView.layer.cornerRadius = 100;
        imageView.layer.borderColor = UIColor.orange.cgColor;
        imageView.layer.borderWidth = 2
        imageView.clipsToBounds = true;
        //交互
        imageView.isUserInteractionEnabled = true;
        let tap = UITapGestureRecognizer.init(target: self, action:#selector(ViewController.tapAction));
        imageView.addGestureRecognizer(tap);
        //設置拉伸模式
        imageView.contentMode = UIViewContentMode.scaleAspectFill;
    
        
    }
    func tapAction(tap:UITapGestureRecognizer) {

        var frame = tap.view?.frame;
        
        frame = CGRect.init(x: 100, y: 100, width: 300, height: 300);
        tap.view?.frame = frame!;
        
        
    }

}

ide

相關文章
相關標籤/搜索