- Installation with CocoaPods:
pod 'MMAdvertScrollView', '~> 1.0.1'
var timeInterval: TimeInterval = 3.0 // 滚动间隔默认为3秒
var scrollDirection: UICollectionView.ScrollDirection = .vertical //默认滚动方向为竖向
var isOnlyShowTitle: Bool = false
let m1 = MMAdvertScrollView(frame: CGRect(x: 0, y: 135, width: UIScreen.main.bounds.width, height: 40))
m1.dataArray = ["恭喜xx,完成了数据管理能力测评。" ,"恭喜xxxxxxxxxxxxxx,完成实名认证。"]
view.addSubview(m1)
@objc protocol MMAdvertScrollViewDelegate: AnyObject{
@objc optional func customCycleScrollViewCellClass(_ cycleView: MMAdvertScrollView) -> AnyClass
@objc optional func customCycleScrollViewNibCellClass(_ cycleView: MMAdvertScrollView) -> AnyClass
func customCycleScrollViewSet(_ collectionViewCell: UICollectionViewCell, numberOfItems item: Int, cycleView view: MMAdvertScrollView )
@objc optional func collectionView(_ cycleView: MMAdvertScrollView, didSelectItemAt indexItem: Int)
}
extension CustomerView: MMAdvertScrollViewDelegate {
// 注册 xib cell
func customCycleScrollViewNibCellClass(_ cycleView: MMAdvertScrollView) -> AnyClass {
return CustomerXIBCell.self
}
func customCycleScrollViewSet(_ collectionViewCell: UICollectionViewCell, numberOfItems item: Int, cycleView view: MMAdvertScrollView) {
let customeCell = collectionViewCell as! CustomerXIBCell
customeCell.titles = ["恭喜xx,完成了数据管理能力测评。", "我是自定义view,而且cell是用xib" ,"恭喜xxxxxxxxxxxxxx,完成实名认证。"]
customeCell.backgroundColor = .yellow
}
}
extension CustomerView2: MMAdvertScrollViewDelegate {
// 注册纯代码cell
func customCycleScrollViewCellClass(_ cycleView: MMAdvertScrollView) -> AnyClass {
return CustomerCollectionViewCell.self
}
func customCycleScrollViewSet(_ collectionViewCell: UICollectionViewCell, numberOfItems item: Int, cycleView view: MMAdvertScrollView) {
let customeCell = collectionViewCell as! CustomerCollectionViewCell
customeCell.titles = ["恭喜xx,完成了数据管理能力测评。", "我是自定义view,而且cell是用纯代码实现的" ,"恭喜xxxxxxxxxxxxxx,完成实名认证。"]
customeCell.backgroundColor = .red
}
}
!Warning:If you customize the Cell, you must implement itcustomCycleScrollViewSet
(如果自定义Cell,必须实现 customCycleScrollViewSet
)
func customCycleScrollViewSet(_ collectionViewCell: UICollectionViewCell, numberOfItems item: Int, cycleView view: MMAdvertScrollView) {
let customeCell = collectionViewCell as! CustomerXIBCell
customeCell.titles = ["恭喜xx,完成了数据管理能力测评。", "我是自定义view,而且cell是用xib" ,"恭喜xxxxxxxxxxxxxx,完成实名认证。"]
customeCell.backgroundColor = .yellow
}
- ARC
- iOS>=10.0