Heinevolder
Heinevolder

Reputation: 338

Add labels inside of ScrollView Xcode Swift

I want to display labels and buttons inside a Scrollview. Can anybody tell me how this is done?

@IBOutlet weak var PeopleView: UIScrollView!

 var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
     button.frame = CGRectMake("INSIDE SCROLL.VIEW", "INSIDE SCROLL.VIEW", 183, 21)
     button.backgroundColor = UIColor.greenColor()
     button.setTitle("Button", forState: UIControlState.Normal)
     button.addTarget(self, action: "Action:", forControlEvents: UIControlEvents.TouchUpInside)
     self.view.addSubview(button)

Upvotes: 0

Views: 3187

Answers (1)

Arun Kumar
Arun Kumar

Reputation: 798

Use this line of code

self.PeopleView.addSubview(button)

instead of

self.view.addSubview(button)

and make sure you are passing a CGFloat value while giving buttons or labels frame

Upvotes: 1

Related Questions