Swift 4.0 轮播图
2017-06-23 本文已影响138人
barry
笔者这两天运用所学到的swift相关东西,写了一个swift版本的轮播图,
一是为了工程需要,
二是对swift进行加深了解,探究一下swift中面向函数编程和面试协议编程。
两种方法
/// 创建图片和文字轮播图
///
/// - Parameters:
/// - frame: 轮播图位置
/// - delegate: SCCycleScrollView代理
/// - imageArray: 图片数据源,默认值nil
/// - titleArray: 文字数据源,默认值[]
/// - placeholderImage: 占位图片
/// - Returns: 返回SCCycleScrollView对象
open class func cycleScrollView(
frame: CGRect, delegate: SCCycleScrollViewDelegate?,
imageArray: [AnyObject]? = nil,
titleArray: [String]? = [],
placeholderImage: UIImage?
) -> SCCycleScrollView
/// 创建文字轮播图
///
/// - Parameters:
/// - frame: 轮播图位置
/// - delegate: SCCycleScrollView代理
/// - titleArray: 文字数据源,默认值[]
/// - Returns: 返回SCCycleScrollView对象
open class func cycleScrollView(
frame: CGRect,
delegate: SCCycleScrollViewDelegate,
titleArray: [String]? = []
)
-> SCCycleScrollView
多种属性
//>>>>>>>>>>>>>>>>>>>>>> SCCycleScrollView属性接口 >>>>>>>>>>>>>>>>>>>>>>>>>>>
/// SCCycleScrollView代理
weak open var delegate: SCCycleScrollViewDelegate?
/// 轮播图滚动方向,默认水平
open var scrollDirection: UICollectionViewScrollDirection = .horizontal
/// 定时时间间隔,默认1.0秒
open var timeInterval: CGFloat = 1.0
//>>>>>>>>>>>>>>>>>>>>>> title属性接口 >>>>>>>>>>>>>>>>>>>>>>>>>>>
/// 文字颜色,默认非纯白(在图片类型和文字类型中通用)
open var titleColor: UIColor = UIColor(red: 0xe5 / 255.0, green: 0xf0 / 255.0, blue: 0xf4 / 255.0, alpha: 1.0)
/// 文字大小,默认18(在图片类型和文字类型中通用)
open var titleFont: UIFont = UIFont.systemFont(ofSize: 18)
/// 文字左侧边距,默认10
open var titleLeftMargin: CGFloat = 10
/// 文字背景条颜色,默认黑色
open var titleContainerBackgroundColor: UIColor? = UIColor.black
/// 文字背景条透明度,默认0.6
open var titleContainerAlpha: CGFloat = 0.6
//>>>>>>>>>>>>>>>>>>>>>> pageControl属性接口 >>>>>>>>>>>>>>>>>>>>>>>>>>>
/// 当前指示器颜色,默认白色
open var currentPageIndicatorTintColor: UIColor = UIColor.white
/// 非选中指示器颜色,默认亮灰色
open var pageIndicatorTintColor: UIColor = UIColor.lightGray
/// pageControl底部边距,默认0
open var pageControlBottomMargin: CGFloat = 0
/// pageControl右侧边距,默认0
open var pageControlRightMargin: CGFloat = 0
/// 只有一张图片时是否隐藏pageControl,默认隐藏
open var isHiddenOnlyPage: Bool = true
/// 外界获取pageControl的size(只读)
open var pageControlSize: CGSize
/// cell类型:图片类型和文字类型
open var cellType: CycleScrollViewCellType?
//>>>>>>>>>>>>>>>>>>>>>> 数据源 >>>>>>>>>>>>>>>>>>>>>>>>>>>
/// 图片数据源
open var imageArray: [AnyObject]?
/// 文字数据源
open var titleArray: [String]?
演示图片
轮播图演示