📦 UISliderView
易于使用和可定制的Swift图片滑动器,具有懒加载图片和全屏查看器
🛠 安装
CocoaPods
CocoaPods是Cocoa项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用CocoaPods将UISliderView
集成到Xcode项目中,请在您的Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!
target '<Your Target Name>' do
pod 'UISliderView', '~> 1.0.2'
end
然后,在项目目录中运行以下终端命令
$ pod install
在您的项目中导入软件包
import UISliderView
💻 如何使用
简单用法
将UISliderView
类设置为自定义类或以编程方式创建UISliderView
类。
@IBOutlet weak var sliderView: UISliderView!
// or
let sliderView = UISliderView()
将图片URL列表设置为sliderView
并运行reloadData()
方法创建/重新加载带有图片的幻灯片
sliderView.images = [
URL(string: "https://source.unsplash.com/1024x1024")!,
URL(string: "https://source.unsplash.com/1024x1024")!,
URL(string: "https://source.unsplash.com/1024x1024")!,
URL(string: "https://source.unsplash.com/1024x1024")!
]
sliderView.reloadData()
完成了!
可用配置
delegate: UISliderViewDelegate?
. 作为滑动视图代理的对象。在主事件中进行通知。viewController: UIViewController?
. 显示全屏滑动器的视图控制器。将此参数设置为全屏打开滑动器。images: [URL]
. 需要加载和显示在滑动器中的图片URL列表。imageContentMode: UIView.ContentMode = .scaleAspectFill
. 幻灯片中的图片内容模式。activityIndicatorColor: UIColor = .black
. 活动指示器的颜色(图片正在加载时)。activityIndicatorStyle: UIActivityIndicatorView.Style?
. 活动指示器样式(图片正在加载时)。pageIndicatorColor: UIColor?
. 页面指示器的颜色。pageCurrentIndicatorColor: UIColor?
. 当前页面指示器的颜色。fullScreenImageContentMode: UIView.ContentMode = .scaleAspectFill
. 全屏幻灯片中的图片内容模式。fullScreenActivityIndicatorColor: UIColor = .white
. 全屏幻灯片(图片加载时)的活动指示器颜色。fullScreenActivityIndicatorStyle: UIActivityIndicatorView.Style?
. 全屏幻灯片(图片加载时)的活动指示器样式。fullScreenBackButtonImage: UIImage?
. 全屏模式下的返回按钮图片。如果未设置图片,自动隐藏按钮。isShowPageControl: Bool = true
. 显示页面控制指示器。
方法
reloadData()
. 通过URL图像列表重新加载幻灯片。在设置图像参数的URL列表后调用此方法。
委托
sliderView(_ sliderView: UISliderView, didChangeSlideAt index: Int)
. 告诉委托幻灯片已更改。sliderView(_ sliderView: UISliderView, didChangeFullScreenVisible isVisible: Bool)
. 告诉委托全屏视图的可视状态已更改。
🚧 需求
- Swift 5.0
- XCode 10
- iOS 11或更高版本
🖖 关于我
- Aleksey Pleshkov
- 邮箱:[email protected]
- 网站:alekseypleshkov.ru
©️ 许可证
UISliderView
根据MIT许可证发布。简而言之,它是免费的,但您必须在其代码或软件发行中保留版权声明。