我有一个可以使用UIScrollView滚动浏览的图像。我想为它添加按钮。按钮需要保持与图像的连接并随之滚动,而不是单独滚动。我需要以编程方式完成这一切。
这是我现在的代码:
imageView = UIImageView(image: UIImage(named: "Map 1.png"))
// 2
scrollView = UIScrollView(frame: view.bounds)
scrollView.backgroundColor = UIColor.blackColor()
// 3
scrollView.contentSize = imageView.bounds.size
// 4
scrollView.addSubview(imageView)
view.addSubview(scrollView)
scrollView.contentSize.height = scrollView.frame.size.height
答案 0 :(得分:0)
你只需要向scrollview添加按钮:
var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Button", forState: UIControlState.Normal)
button.addTarget(self, action: "Action:", forControlEvents: UIControlEvents.TouchUpInside)
scrollView.addSubview(button)