search
Homephp教程PHP开发Swift study notes 1 hello world
Swift study notes 1 hello worldSep 14, 2018 am 09:58 AM
swift

I have been studying PHP for more than a year now, and I have accumulated a lot of notes, which are quite complicated. Let me write an article to sort them out.

Learning any language starts from hello world, hahaha

Start my swift learning journey

//这个好像就是类似于OC的懒加载 (个人观点--菜鸡观点)
    fileprivate var helloBtn: UIButton = {

        let  helloBtn = UIButton(type:.custom)   //初始化UIButton 
        helloBtn.frame = CGRect(x: 100, y: 100, width: 205, height: 50) //设置frame
        helloBtn.backgroundColor = UIColor.blue     //设置背景颜色
        helloBtn.setTitle("欢迎", for: UIControlState.normal) //设置title (普通状态下)
        helloBtn.setTitleColor(UIColor.white, for: .normal)  //设置title的颜色 (普通状态下)
        helloBtn.setTitle("hello world", for: UIControlState.selected) //设置title (点击状态下)
        helloBtn.addTarget(self, action: #selector(helloBtnClick), for: .touchUpInside)  //添加点击事件
        return helloBtn
    }()

As for what effect we need to achieve, let’s wait for the code Finished

After initializing a button OK, you need to load it on the View and display it

 //这个方法相当于 OC里的 -(void)viewDidLoad;
    override func viewDidLoad() {
        super.viewDidLoad()

        //在view上添加一个按钮
        self.view .addSubview(helloBtn)
    }

ok, but there is still a click event method

extension ViewController{
    

//这个就是点击事件出发的方法
    @objc fileprivate func helloBtnClick(sender :UIButton){
        
//改变状态
        sender.isSelected = !sender.isSelected;
        
    }
}

Related recommendations:

Study Standards - Notes_Experience Exchange

php Basic knowledge of study notes

The above is the detailed content of Swift study notes 1 hello world. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
苹果发布用于同态加密的开源 Swift 软件包,已部署在 iOS 18 中苹果发布用于同态加密的开源 Swift 软件包,已部署在 iOS 18 中Jul 31, 2024 pm 01:10 PM

7月31日消息,苹果公司昨日(7月30日)发布新闻稿,宣布推出新的开源Swift包(swift-homomorphic-encryption),用于在Swift编程语言中启用同态加密。注:同态加密(HomomorphicEncryption,HE)是指满足密文同态运算性质的加密算法,即数据经过同态加密之后,对密文进行特定的计算,得到的密文计算结果在进行对应的同态解密后的明文等同于对明文数据直接进行相同的计算,实现数据的“可算不可见”。同态加密技术可以计算加密数据,而且不会向操作过程泄露底层的未加

Vue.js与Swift语言的集成,实现高级iOS应用的开发和测试的建议Vue.js与Swift语言的集成,实现高级iOS应用的开发和测试的建议Aug 01, 2023 am 09:53 AM

Vue.js是一种流行的JavaScript框架,用于构建用户界面。而Swift语言是一种用于iOS和macOS应用程序开发的编程语言。在本文中,我将探讨如何将Vue.js与Swift语言集成,以实现高级iOS应用程序的开发和测试。在开始之前,我们需要确保你已经安装了以下软件和工具:Xcode:用于开发和编译iOS应用程序的集成开发环境。Node.js:用于

如何使用MySQL在Swift中实现数据导入和导出功能如何使用MySQL在Swift中实现数据导入和导出功能Aug 01, 2023 pm 11:57 PM

如何使用MySQL在Swift中实现数据导入和导出功能导入和导出数据是许多应用程序中常见的功能之一。本文将展示在Swift语言中使用MySQL数据库实现数据导入和导出的方法,并提供代码示例。要使用MySQL数据库,首先需要在Swift项目中引入相应的库文件。你可以通过在Package.swift文件中添加以下依赖来实现:dependencies:[

如何使用Redis和Swift开发实时聊天功能如何使用Redis和Swift开发实时聊天功能Sep 20, 2023 pm 12:31 PM

如何使用Redis和Swift开发实时聊天功能引言:实时聊天功能已经成为现代社交应用中不可或缺的一部分。在开发社交应用时,我们经常需要使用实时聊天来提供用户之间的互动和信息交流。为了达到实时性和高可用性的要求,我们可以使用Redis和Swift来开发这样一个功能。Redis简介:Redis是一个开源的内存数据结构存储系统,也被称为数据结构服务器。它通过提供多

与Go接近的编程语言有哪些?与Go接近的编程语言有哪些?Mar 23, 2024 pm 02:03 PM

与Go接近的编程语言有哪些?近年来,Go语言在软件开发领域逐渐崭露头角,受到越来越多开发者的青睐。虽然Go语言本身拥有简洁、高效和并发性强的特点,但有时候也会遇到一些限制和不足。因此,寻找与Go语言接近的编程语言成为了一种需求。下面将介绍一些与Go语言接近的编程语言,并通过具体代码示例展示它们的相似之处。RustRust是一种系统编程语言,注重安全性和并发性

如何使用Redis和Swift开发推荐系统功能如何使用Redis和Swift开发推荐系统功能Sep 21, 2023 pm 02:09 PM

如何使用Redis和Swift开发推荐系统功能在当今互联网时代,推荐系统已经成为许多应用的核心功能之一。无论是电商平台、社交网络还是音乐视频网站,都广泛使用推荐系统来提供个性化的推荐内容,帮助用户发现并获取他们可能感兴趣的内容。要实现一个高效和准确的推荐系统,Redis和Swift是两个强大的工具,可以通过它们的组合来实现一个强大的推荐功能。Redis是一个

Java函数与Swift语言函数的区别?Java函数与Swift语言函数的区别?Apr 24, 2024 am 08:21 AM

Java和Swift函数的主要区别在于:语法、类型系统、返回值、修饰符和参数类型指定方式。

Vue.js与Swift语言的集成,实现高级iOS应用的开发和测试的建议和技术指导Vue.js与Swift语言的集成,实现高级iOS应用的开发和测试的建议和技术指导Jul 29, 2023 pm 01:06 PM

Vue.js与Swift语言的集成,实现高级iOS应用的开发和测试的建议和技术指导引言移动应用的开发和测试是一个复杂而且需要专业技术的领域。两个主要的技术栈分别是前端的Vue.js和iOS平台的Swift语言。本文将介绍如何将Vue.js和Swift语言进行集成,以便开发和测试高级的iOS应用。Vue.js的基本原理和功能Vue.js是一种用于构建用户界面的

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment