๐ผ ImageSlideshow
Customizable Swift image slideshow with circular scrolling, timer and full screen viewer
Image Slide show ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ฌ๋ฌ ์ด๋ฏธ์ง๋ฅผ ์์ผ๋ก ์ฌ๋ผ์ด๋ํ๋ UI ๋ฅผ ๊ตฌํํด์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค! ์ธ์คํ๊ทธ๋จ์ ์ด๋ฏธ์ง๊ฐ ๋ํ๋๋ ๊ฒ์ ๊ตฌํํ ์ ์์ต๋๋ค.
๋ค์์ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํ๊ณ ์์ต๋๋ค.
- ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋์ ์ํ ๊ตฌ๋ถ์(circular indicator) ์ด์ฉ
- ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋์ Label Indicator (ex 1/5) ์ ๊ณต
- ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋๊ฐ ๊ฐ๋ฅํ Full screen view ์ ๊ณต
- ์๊ฐ์ ์ค์ ํด ์๋์ผ๋ก ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋๊ฐ ๊ฐ๋ฅํ๋๋ก ์ ๊ณต
zvonicek/ImageSlideshow
Swift image slideshow with circular scrolling, timer and full screen viewer - zvonicek/ImageSlideshow
github.com
๐ง Installation
์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ํ๋ก์ ํธ์ ํฌํจ์ ๋จผ์ ์์ผ์ค์ผ๊ฒ ์ฃ ?! ์ ๋ CocoaPods ์ ์ด์ฉํ๊ธฐ ๋๋ฌธ์, [ pod init > Podfile ์์ > pod install ] ์ดํ ์์ฑ๋ Project.xcworkspace ํ์ผ์ ์ด์ฉํด ๊ฐ๋ฐํ์ต๋๋ค. Podfile ์ ์๋ ์ฝ๋๋ฅผ ํ ์ค ์ถ๊ฐํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
pod 'ImageSlideshow', '~> 1.9.0'
๐จ How to use
1. ImageSlideShow ํด๋์ค์ View ์์ฑํ๊ธฐ
ImageSlideshow ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํ๊ธฐ ์ํด์ ๋จผ์ , ImageSlideshow ํด๋์ค์ View ๋ฅผ ์์ฑํด์ฃผ์ด์ผ ํฉ๋๋ค. Storyboar ๋ฅผ ์ด์ฉํ๋ค๋ฉด UIView ๋ฅผ ์ถ๊ฐํ๊ณ , Custom Class ๋ฅผ ImageSlideshow ๋ก ์ง์ ํด์ฃผ์๋ฉด ๋ฉ๋๋ค.

2. ImageSlideShow ์ ์ด๋ฏธ์ง ์ค์ ํ๊ธฐ
์ดํ, ImageSlideshow ์ ์ด๋ฏธ์ง๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค. UIImage ๋ฅผ ์ด์ฉํ๋ค๋ฉด ๋ฐ๋ก ์ฌ์ฉํ ์ ์์ง๋ง, AlamofireImage, SDWebImage, Kingfisher ์ ๊ฐ์ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ณ๋์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ ์ค์น๊ฐ ํ์ํฉ๋๋ค. Github ๋ฌธ์์์ ์ค์นํด์ผํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ธํ์ค ์ ์์ด์.
์งํ์ค์ธ ํ๋ก์ ํธ๋ Firebase Storage ์์ ์ด๋ฏธ์ง๋ฅผ ๊ด๋ฆฌํ๊ณ ์๊ธฐ ๋๋ฌธ์ Firebase UI ์ ํฌํจ๋ SDWebImage ๋ฅผ ์ด์ฉํ์ต๋๋ค. ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด์ฉํ๋ Github ๋ฌธ์์ ์์ ๊ฐ ์์ด์ ๊ฑฑ์ ํ์ง๋ง, ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋น์ทํฉ๋๋ค. ImageInputs.append(SDWebImageSource(url: url)) ์ฝ๋๋ง ์ฐธ๊ณ ํ์๋ฉด ๋ผ์!
ํน์ Firebase Storage ์ Image Slide show ๋ฅผ ํจ๊ป ์ด์ฉํ์๋ ๋ถ๊ป ๋์์ด ๋ ๊นํด์ ์ฝ๋ ํจ๊ป ์ฒจ๋ถํฉ๋๋ค. ๐
import ImageSlideshow
struct FirebaseStorage {
static let baseURL = "https://firebasestorage.googleapis.com/v0/b/bucket-name/o/"
static let query = "?alt=media"
static func getImageInputs(images: [Image]) -> [SDWebImageSource] {
var imageInputs: [SDWebImageSource] = []
for image in images {
let path = image.pictureUrl.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
let url = URL(string: baseURL + path + query)!
imageInputs.append(SDWebImageSource(url: url))
}
return imageInputs
}
}
์์ ํจ์๋ฅผ ImageSlideshow ๊ฐ ์๋ ViewController ์์ ์ด์ฉํด์ฃผ์๋ฉด ๋ฉ๋๋ค! ์ฝ๋์์ ์ด์ฉํ ImageSlideshow ์ ์ธ์๋ค์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- func setImageInputs(_ inputs: [InputSource]) :: ์ด๋ฏธ์ง ์ค์
- var contentScaleMode :: ์ด๋ฏธ์ง ์ค์ผ์ผ ์ค์ (UIView.ContentMode ์ ๋์ผํฉ๋๋ค)
- var pageIndicatorPosition :: ํ์ด์ง ๊ตฌ๋ถ์๊ฐ ๋ํ๋๋ ์์น ์ค์
class CustomViewController {
// ...
private func updateImageSlide(_ shopImages: [Image]) {
// Firebase Storage ์ด๋ฏธ์ง ์ฐ๋
let imageInputs = FirebaseStorage.getImageInputs(images: shopImages)
shopImageSlide.setImageInputs(imageInputs)
shopImageSlide.contentScaleMode = .scaleAspectFill
shopImageSlide.pageIndicatorPosition = .init(horizontal: .center, vertical: .bottom)
}
}
์ ์์ ์ผ๋ก ๊ตฌํ์ ๋ค์๊ณผ ๊ฐ์ ํ๋ฉด์ ๋ง๋์ค ์ ์์ต๋๋ค. ๐คฉ ๊ตฌํ์ค์ธ ์ฑ์ ์ผ๋ถ์ด๊ณ , ์ฌ์ง์ ๋ธ๋ฆฟ์ง์ฃ์ง ์นดํ์์ ์ ๊ณต๋ฐ์์ต๋๋ค.


๋ค์ ํฌ์คํ ์์ Label Indicator, Full screen view ์ ์ฉํ๊ธฐ๋ฅผ ๋ค๋ค๋ณด๊ฒ ์ต๋๋ค.
[iOS/Swift] Image Slide show - Label Page Indicator, Full screen view ๊ตฌํํ๊ธฐ
๐ผ ImageSlideshow ImageSlideshow ์ค์น, ๋ทฐ ์์ฑํ๊ธฐ, ์ด๋ฏธ์ง ๋ฑ๋กํ๋ ๋ฒ์ ์ด์ ํฌ์คํ ์ ์ฐธ๊ณ ํด์ฃผ์ธ์. ํด๋น ํฌ์คํ ์์๋ Label Page Indicator ์ ์ฉํ๋ ๋ฒ, ์ด๋ฏธ์ง ํด๋ฆญ์ ์ ์ฒด ํ๋ฉด์ผ๋ก ์ ํํ๋ ๋ฒ์
jellysong.tistory.com
์ฐธ๊ณ ๋งํฌ