Skip to content

Instantly share code, notes, and snippets.

@seit
seit / CarouselView.swift
Created November 25, 2024 07:44
iOSアプリでカルーセルを作ってみた 3
HStack(spacing: imagePadding) { // add spacing
ForEach(0..<5) { index in
ZStack {
RoundedRectangle(cornerRadius: 10)
.frame(width: imageSize.width, height: imageSize.height)
.foregroundStyle(
Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
@seit
seit / CarouselView.swift
Last active November 26, 2024 01:21
iOSアプリでカルーセルを作ってみた 2
import SwiftUI
struct CarouselView: View {
@State private var currentPage: Int = 0
@State private var contentOffset: CGPoint = CGPoint(x: 0, y: 0)
/// 画像と画像の隙間
private let imagePadding: CGFloat = 8
/// 見切れのサイズ
@seit
seit / PagingScrollView.swift
Last active December 2, 2024 02:09
iOSアプリでカルーセルを作ってみた 1
import SwiftUI
public struct PagingScrollView<Content: View>: UIViewRepresentable {
let content: () -> Content
let disScroll: (CGPoint) -> Void
let disScrollEnd: () -> Void
public init(
@ViewBuilder _ content: @escaping () -> Content,
disScroll: @escaping (CGPoint) -> Void,