Post

Replies

Boosts

Views

Activity

Reply to Image slider
import SwiftUI struct Tab1: View { private var numberOfImages = 3 private let timer = Timer.publish(every: 10, on: .main, in: .common) .autoconnect() @State private var currentIndex = 0 var body: some View {   GeometryReader { proxy in   TabView(selection:$currentIndex) {     ForEach(0..<numberOfImages) {num in Image("\(num)")       .resizable()       .scaledToFill()        .overlay(Color.black.opacity(0.4))       .tag(num)  } }.tabViewStyle(PageTabViewStyle())       .clipShape(RoundedRectangle(cornerRadius: 10)) .frame(width: proxy.size.width, height: proxy.size.height/ 3)          .onReceive(timer, perform: { _ in                 withAnimation {                 currentIndex = currentIndex < numberOfImages ? currentIndex + 1 : 0                 }             })         }      } } struct Tab1_Previews: PreviewProvider {     static var previews: some View {         Tab1()     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’21