99热99这里只有精品6国产,亚洲中文字幕在线天天更新,在线观看亚洲精品国产福利片 ,久久久久综合网

歡迎加入QQ討論群258996829
Limandy 頭像
蘋果0袋
0
Limandy

在按鈕點擊事件方法中如何攻取另一個控件的位置及大小

發(fā)布時間:2019-01-29 19:13  回復(fù):2  查看:8359   最后回復(fù):2019-10-17 15:02  
//
//  ViewController.swift
//  buttondemo
//
//  Created by Andy on 2019/1/29.
//  Copyright ? 2019 Limi. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let button = UIButton.init(type: .custom)
        let buttonimg = UIButton(type: .custom)
        button.frame = CGRect(origin: .init(x: 50, y: 500), size: .init(width: 100, height: 100))
        button.backgroundColor = .red
        buttonimg.frame = CGRect(origin: .init(x: 50, y: 50), size: .init(width: 300, height: 300))
        buttonimg.backgroundColor = .black
        button.setTitle("請點擊", for: .normal)
        button.setTitleColor(UIColor.red, for: .normal)
        button.addTarget(self, action: #selector(dianji), for: .touchUpInside)
        
        view.addSubview(button)
        view.addSubview(buttonimg)
    }
    
    
    @IBAction func dianji(){
      var a =  self.buttonimg.frame
    //這里會報錯,求解,實在是不知道怎么搞了
    //Value of type 'ViewController' has no member 'buttonimg'
   //大意是:ViewController 沒有 buttonimg這個對象
    print("hello")
    }


}
HelloWorld1986 頭像
蘋果0袋
0
HelloWorld1986   2019-02-15 14:33
        let buttonimg = UIButton(type: .custom)

放到viewDidLoad外
您還未登錄,請先登錄

熱門帖子

最新帖子

?