【发布时间】:2020-01-26 03:42:44
【问题描述】:
我正在运行 Xcode 11,并且希望能够在 UIScrollView 在 6 页设置中从一个页面移动到另一个页面时更改它的背景颜色。我已经能够更改每个页面的标签内容,但背景颜色“跳过”到颜色数组中的最后一个。
数组:
let stringArray = ["<- Swipe to begin", "Welcome", "Info", "more info", "more info 2", "end"]
let backgroundColorArray = [UIColor.orange, UIColor.blue, UIColor.red, UIColor.white, UIColor.green, UIColor.purple]
然后是scrollview内容
func setupScrollView() {
scrollView.delegate = self
scrollView.contentSize = CGSize(width: self.view.frame.size.width * 6, height: scrollView.frame.size.height)
for k in 0 ... 5 {
scrollView.backgroundColor = backgroundColorArray[k]
}
for i in 0 ... 5 {
let label = UILabel(frame: CGRect(x: scrollView.center.x + CGFloat(i) * self.view.frame.size.width - 130, y: 50, width: 260, height: 30))
label.font = UIFont.boldSystemFont(ofSize: 26)
label.textAlignment = .center
label.text = stringArray[i]
scrollView.addSubview(label)
}
}
滚动视图背景颜色变为紫色,但不会因页面而异。改变颜色的正确方法是什么?
【问题讨论】:
标签: ios swift uiscrollview