在ScrollView Xcode Swift中添加标签

时间:2014-11-21 13:32:22

标签: ios xcode swift uiscrollview

我想在Scrollview中显示标签和按钮。 谁能告诉我这是怎么做到的?

@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)

1 个答案:

答案 0 :(得分:1)

使用此行代码

self.PeopleView.addSubview(button)

而不是

self.view.addSubview(button)

并确保在提供按钮或标签框架时传递CGFloat