Use UICollectionView implement common image/text infinite shuffling, support custom pageControl, custom text styles, and the wheel style, the code is simple, easy to use making: https://github.com/MQZHot/ZCycleView
The basic use
let cycleView = ZCycleView(frame: frame)
cycleView.placeholderImage = UIImage(named: "placeholder")
cycleView.setUrlsGroup(["http://..."."http://..."."http://..."], titlesGroup: ["..."."..."])
view.addSubview(cycleView)Copy the code
You can set local images, image urls, and display text only
When you set text, you can choose either the title group or the attributed title group, both of which are arrays, and if both are set, the attributedTitlesGroup is preferred
/// image
func setImagesGroup(_imagesGroup: Array<UIImage? >, titlesGroup: [String?] ? =nil, attributedTitlesGroup: [NSAttributedString?] ? =nil)
/// image url
func setUrlsGroup(_urlsGroup: Array<String>, titlesGroup: [String?] ? =nil, attributedTitlesGroup: [NSAttributedString?] ? =nil)
/// text only
func setTitlesGroup(_titlesGroup: Array<String? >? , attributedTitlesGroup: [NSAttributedString?] ? =nil)
`Copy the code
If you want to add a picture to the left of the text, as shown below, you need to call the following method note: Be sure to set the size of the picture, otherwise it will not be displayed
func setTitleImagesGroup(_titleImagesGroup: [UIImage?] , sizeGroup:[CGSize?] )
/ / / or
func setTitleImageUrlsGroup(_titleImageUrlsGroup: [String?] , sizeGroup:[CGSize?] )Copy the code
Set picture item
/ / / size
var itemSize: CGSize?
/// The size of the middle item
var itemZoomScale: CGFloat = 1
/// item spacing
var itemSpacing: CGFloat = 0
/ / / rounded corners
var itemCornerRadius: CGFloat = 0
/// frame color
var itemBorderColor: UIColor = UIColor.clear
/// frame width
var itemBorderWidth: CGFloat = 0Copy the code
For example, the middle item is magnified 1.2 times
cycleView.itemSize = CGSize(width: 240, height: 90)
cycleView.itemZoomScale = 1.2Copy the code
Set the text
The image above sets attributedTitlesGroup. If you want to display multiple lines, you need to set titleNumberOfLines = 0
// the height of the text
var titleViewHeight: CGFloat = 25
/// align
public var titleAlignment: NSTextAlignment=.left
/// font size
public var titleFont: UIFont = UIFont.systemFont(ofSize: 13)
/// Background color
public var titleBackgroundColor: UIColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5)
/// Text color
public var titleColor: UIColor = UIColor.white
/// display the number of lines
public var titleNumberOfLines = 1
/// line break mode
public var titleLineBreakMode: NSLineBreakMode = .byWordWrappingCopy the code
Set the pageControl
PageControl allows you to customize unselected sizes, colors, shapes, etc., as well as images
/// Whether to hide pageControl
var pageControlIsHidden = false
/// Dot color
var pageControlIndictirColor = UIColor.gray
/// Select the dot color
var pageControlCurrentIndictirColor = UIColor.white
/// select the dot image
var pageControlCurrentIndictorImage: UIImage?
/// dot image
var pageControlIndictorImage: UIImage?
/// pageControl height
var pageControlHeight: CGFloat = 25
/// PageControl background color
var pageControlBackgroundColor = UIColor.clear
/// Dot size
var pageControlItemSize = CGSize(width: 8, height: 8)
/// Select the dot size
var pageControlCurrentItemSize: CGSize?
/// The distance between dots
var pageControlSpacing: CGFloat = 8
/// align
var pageControlAlignment: ZCyclePageControlAlignment = .center
/ / / rounded corners
var pageControlItemRadius: CGFloat?
/// select the rounded corner
var pageControlCurrentItemRadius: CGFloat?Copy the code
Click events/slide events use closures
/// click
var didSelectedItem: ((Int) - > ())?/// scroll
var didScrollToIndex: ((Int) - > ())?Copy the code
Other attributes
/// automatically scroll
var isAutomatic: Bool = true
/// whether to scroll indefinitely
var isInfinite: Bool = true
/// The time interval for scrolling
var timeInterval: Int = 2
/// scroll direction
var scrollDirection: UICollectionViewScrollDirection = .horizontal
/ / / placeholder figure
var placeholderImage: UIImage? = nilCopy the code
Rely on
Kingfisher
The use of detailed look at the demo, there is a problem making welcome feedback: https://github.com/MQZHot/ZCycleView