我在IB上的UIView中有两个UIScrollViews。
每个UIScrollView都有水平按钮。 顶部UIScrollView上的按钮高度为70 底部UIScrollView上的按钮高度为60 然后添加一些填充,即10px
所以我将UIScrollViews设置为一个,其中一个按钮是视图的一半,另一个是UIScrollView中的按钮,但没有任何填充。
有关将UIScrollViews添加到UIView的任何建议,以便它们正确放置并且不进行任何垂直滚动(仅水平),并且按钮适合UIScrollView。
这是设置UIScrollViews的代码。
let scrollingView = ScrollViewEventType(CGSizeMake(62.0,62.0), buttonCount: 10)
EventScroll.contentSize = scrollingView.frame.size
EventScroll.addSubview(scrollingView)
EventScroll.showsHorizontalScrollIndicator = false
EventScroll.indicatorStyle = .Default
let datescrollingview = ScrollViewDateType(CGSizeMake(124.0, 70.0), buttonCount: 6)
DateScroll.contentSize = datescrollingview.frame.size
DateScroll.addSubview(datescrollingview)
DateScroll.showsHorizontalScrollIndicator = false
DateScroll.indicatorStyle = .Default
这是针对两个UIScrollViews
func ScrollViewEventType(buttonSize:CGSize, buttonCount:Int) -> UIView {
//creates color buttons in a UIView
let padding = CGSizeMake(10, 10)
let buttonView = UIView()
DateScroll.backgroundColor = UIColor(red: 0.84, green: 0.90, blue: 0.95, alpha: 1.0)
DateScroll.frame.origin = CGPointMake(0, 2)
buttonView.frame.size.width = (buttonSize.width + padding.width) * CGFloat(buttonCount)
buttonView.frame.size.height = (buttonSize.height + padding.height)
//add buttons to the view
var buttonPosition = CGPointMake(padding.width * 0.5, padding.height)
let buttonIncrement = buttonSize.width + padding.width
for i in 0...(buttonCount - 1) {
var button = UIButton.buttonWithType(.Custom) as UIButton
button.frame.size = buttonSize
button.frame.origin = buttonPosition
buttonPosition.x = buttonPosition.x + buttonIncrement
button.backgroundColor = UIColor(red: 0.13, green: 0.48, blue: 0.81, alpha: 1.0)
button.tag = i
button.addTarget(self, action: "EventButtonPressed:", forControlEvents: .TouchUpInside)
buttonView.addSubview(button)
}
return buttonView
}