我想在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)
答案 0 :(得分:1)
使用此行代码
self.PeopleView.addSubview(button)
而不是
self.view.addSubview(button)
并确保在提供按钮或标签框架时传递CGFloat
值