Swift study notes 1 hello world
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

According to news on July 31, Apple issued a press release yesterday (July 30), announcing the launch of a new open source Swift package (swift-homomorphic-encryption) for enabling homomorphic encryption in the Swift programming language. Note: Homomorphic Encryption (HE) refers to an encryption algorithm that satisfies the homomorphic operation properties of ciphertext. That is, after the data is homomorphically encrypted, specific calculations are performed on the ciphertext, and the obtained ciphertext calculation results are processed at the same time. The plaintext after state decryption is equivalent to directly performing the same calculation on the plaintext data, achieving the "invisibility" of the data. Homomorphic encryption technology can calculate encrypted data without leaking the underlying unencrypted data to the operation process.

Vue.js is a popular JavaScript framework for building user interfaces. The Swift language is a programming language used for iOS and macOS application development. In this article, I will explore how to integrate Vue.js with the Swift language for advanced iOS application development and testing. Before we get started, we need to make sure you have the following software and tools installed: Xcode: an integrated development environment for developing and compiling iOS applications. Node.js: used for

How to implement data import and export functions in Swift using MySQL Importing and exporting data is one of the common functions in many applications. This article will show how to use MySQL database to import and export data in Swift language, and provide code examples. To use the MySQL database, you first need to introduce the corresponding library files into the Swift project. You can do this by adding the following dependencies in the Package.swift file: dependencies:[

How to develop real-time chat function using Redis and Swift Introduction: Real-time chat function has become an indispensable part of modern social applications. When developing social applications, we often need to use real-time chat to provide interaction and information exchange between users. In order to meet the requirements of real-time and high availability, we can use Redis and Swift to develop such a function. Introduction to Redis: Redis is an open source in-memory data structure storage system, also known as a data structure server. It provides multiple

What programming languages are close to Go? In recent years, the Go language has gradually emerged in the field of software development and is favored by more and more developers. Although the Go language itself has the characteristics of simplicity, efficiency and strong concurrency, it sometimes encounters some limitations and shortcomings. Therefore, looking for a programming language that is close to the Go language has become a need. The following will introduce some programming languages close to the Go language and demonstrate their similarities through specific code examples. RustRust is a systems programming language with a focus on safety and concurrency

Integration of Vue.js and Swift language, suggestions and technical guidance for the development and testing of advanced iOS applications. Introduction The development and testing of mobile applications is a complex field that requires professional skills. The two main technology stacks are Vue.js on the front end and Swift language on the iOS platform. This article will introduce how to integrate Vue.js and Swift language to develop and test advanced iOS applications. Fundamentals and features of Vue.js Vue.js is a tool for building user interfaces

How to use Redis and Swift to develop recommendation system functions In today's Internet era, recommendation systems have become one of the core functions of many applications. Whether it is e-commerce platforms, social networks or music video websites, recommendation systems are widely used to provide personalized recommended content and help users discover and obtain content that may be of interest to them. To implement an efficient and accurate recommendation system, Redis and Swift are two powerful tools that can be combined to achieve a powerful recommendation function. Redis is a

Application of Go and Swift in high-performance computing: Go: concurrency and communication, achieving high performance with its goroutine mechanism and communication mechanism (channels and selectors). Swift: Efficient memory management, utilizing ARC and memory safety checker to ensure efficient memory management and avoid performance bottlenecks.
