Reputation: 7094
I have a ViewController
and I want to add 3 subviews in the content part.
On the top i would put some 3-line fixed text and then tabBar (or segment control, I don't know what is best) and then subview.
I want to create something such that it looks like this image example:
Specifically, my questions are:
Upvotes: 2
Views: 7199
Reputation: 13
Add two button in the main storyboard view object. Set button text, and background color to green. You can read iOS Add Click Event To UIButton Swift Example to learn how to add button click event function.
import UIKit
class ViewController: UIViewController {
// Create the subview object.
private let childView = UIView();
// When click the second button will invoke this method.
@IBAction func removeSubView(_ sender: UIButton, forEvent event: UIEvent) {
// Remove the child view.
childView.removeFromSuperview();
}
// Invoked when click the first button.
@IBAction func addSubView(_ sender: UIButton, forEvent event: UIEvent) {
// Add the child view.
self.view.addSubview(childView);
}
override func viewDidLoad() {
super.viewDidLoad()
// Set child view x y cordinate and size.
childView.frame = CGRect(x: 80, y: 100, width: 200, height: 100)
// Set child view background color.
childView.backgroundColor = UIColor.green
}
}
Upvotes: 0
Reputation: 1816
create an IBoutlet in your header file and synthesize it. hold conrtol and drag it to your header file. choose iboutlet give it a name. you are good to go. then use your outlet
[self.myview addSubview:mysubview]
Upvotes: 1