How to use the code add button in the iOS11 application view
This article mainly introduces how to use the code add button in the iOS11 application view, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
This is not covered because it is relatively easy to add views using the editing interface. Here, I will directly explain how to add it to the code. Use the code to add a button in the main view in the same way as the steps explained in Section 1.3.3. First, you need to instantiate a button object using the UIButton class, then set the position and size, and finally add the button object to the main view using the addSubview () method. (since views are all added in the same way, the use of code to add views will be omitted later. ).
[example 2-1] the following will add a button object with an orange background in the main view. The code is as follows:
Import UIKit
Class ViewController: UIViewController {
Override func viewDidLoad () {
Super.viewDidLoad ()
/ / Do any additional setup after loading the view, typically from a nib.
/ / add button object
Let button=UIButton (frame: CGRect (x: 143,241, width: 88, height: 30))
Button.backgroundColor=UIColor.orange
Self.view.addSubview (button)
}
……
}
When you run the program at this point, you will see the effect shown in figure 2.2.
Figure 2.2 Operation effect
Note: the orange area shown in figure 2.2 is actually the add button.
Thank you for reading this article carefully. I hope the article "how to use the Code add Button in the iOS11 Application View" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!