前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >swift 5.0 创建button方法

swift 5.0 创建button方法

作者头像
用户1219438
发布2020-04-23 17:15:47
1.4K0
发布2020-04-23 17:15:47
举报
文章被收录于专栏:AliceAlice
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    
        //创建视图
        let redV = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        
        //设置视图的背景颜色
        redV.backgroundColor = UIColor.red;
        
        //添加到当前页面
        view.addSubview(redV);
        redV.center = view.center;
    
        
        let btn = UIButton(type: .contactAdd);
        redV .addSubview(btn);

        
        btn.addTarget(self, action: #selector(btnClicked), for: .touchUpInside);
        
    }

    @objc func btnClicked()->String{
        print(#function);
        return "111";
    }
}

swift 创建 imageview

    let img = UIImageView(frame: CGRect(x: 100, y: 300, width: 50, height: 50))
    view .addSubview(img)
    img.image = UIImage.init(named: "22");    
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档