In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how iOS11 application view to achieve button response, has a certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.
In this case, when the user taps the button, a method called tapButton() is triggered.
Note: The above one way is action declaration and association together, there is also a way to declare the action first and then associate. Declaring actions can use the keyword IBAction. This keyword tells the story panel interface that this method is an action and can be triggered by a control. The syntax for declarative actions is as follows:
@IBAction func Action Name (_Parameter: Parameter Type){
}
Figure 2.10 shows the action declaration code written in the ViewController.swift file.
Figure 2.10 Declared Actions
Note: After the action is declared, a small hollow circle appears in front of the code to indicate that the action has not been associated.
After declaring the action, you can associate it. First, use the tools in the adjustment window to adjust the Xcode interface. Adjust it to look like Figure 2.5.
Then, hold down Ctrl and drag the button object in the interface. A blue line will appear, associating this blue line with the action in the file ViewController.swift, as shown in Figure 2.11.
Figure 2.11 Correlated actions
Finally, after releasing the mouse, the button object is successfully associated with the action. At this time, the small hollow circle in front of the action becomes a small solid circle, indicating that the action has been associated. The effect is the same as Figure 2.9.
(8) Open the ViewController.swift file and write code that will implement the button response. The code is as follows:
import UIKit
class ViewController: UIViewController {
var isYellow:Bool=false
@IBAction func tapButton(_ sender: AnyObject) {
//Determine if the background of the main view is yellow
if(isYellow){
self.view.backgroundColor=UIColor.white //Set background color
isYellow=false
}else{
self.view.backgroundColor=UIColor.yellow
isYellow=true
}
}
……
}
Run the program at this point, and you will first see the effect shown in Figure 2.12. When you tap Tap me,Change View Color, the background of the main view changes to yellow, as shown in Figure 2.13. When you tap Tap me,Change View Color again, the background color of the main view will change back to white.
Figure 2.12 Operation Effect Figure 2.13 Operation Effect
Thank you for reading this article carefully, I hope Xiaobian shared "iOS11 application view how to achieve button response" This article is helpful to everyone, but also hope that everyone more support, pay attention to the industry information channel, more relevant knowledge waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.