gpt4 book ai didi

ios - 如何在 Swift 中让按钮随背景滚动?

转载 作者:行者123 更新时间:2023-11-30 14:18:41 26 4
gpt4 key购买 nike

我有一个可以使用 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

最佳答案

你只需要添加按钮到 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)

关于ios - 如何在 Swift 中让按钮随背景滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com