Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Tailoring nanoscale interfaces for perovskite–perovskite–silicon triple-junction solar cells

    October 13, 2025

    SGLA criticizes California Governor Newsom for signing ‘flawed, rushed’ sweepstakes ban

    October 13, 2025

    Gesture Recognition for Busy Hands

    October 13, 2025
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – Issue LiveActivity Timer Layout
    iOS Development

    ios – Issue LiveActivity Timer Layout

    big tee tech hubBy big tee tech hubSeptember 21, 2025003 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – Issue LiveActivity Timer Layout
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I’m trying to make a simple timer in a LiveActivity on iOS but I keep having some issues with a layout when I use Text(timerInterval:) solution.

    • If I use Text(timerInterval:) this is how it looks in the Dynamic Island and Lock Screen

    enter image description here

    enter image description here

    • If I use a simple calculation it looks good in layout but it does not update the counting.

    What could be wrong? I tried to follow the simple timer tutorials but i can’t find the issue.

    PD: I’m not an iOS dev 🙂

    This is the LiveActivity lockScreen section and Attributes

    struct TimerAttributes: ActivityAttributes {
        public typealias TimerStatus = ContentState
    
        public struct ContentState: Codable, Hashable {
            // Only changeable state goes here
            var isPaused: Bool
            var isCompleted: Bool = false
    
            // Display data
            var taskTitle: String
            var taskColor: String // Color as hex string for serialization
    
            // Note: These functions now need to be called with attributes parameter
            func getRemainingTime(endDate: Date, at date: Date = Date()) -> TimeInterval {
                if isCompleted {
                    return 0
                }
                return max(0, endDate.timeIntervalSince(date))
            }
    
            func getElapsedTime(startDate: Date, at date: Date = Date()) -> TimeInterval {
                return max(0, date.timeIntervalSince(startDate))
            }
    
            func isTimerRunning(endDate: Date, at date: Date = Date()) -> Bool {
                return !isPaused && !isCompleted && getRemainingTime(endDate: endDate, at: date) > 0
            }
    
            // Helper methods matching the working SimpleTimer approach
            func getElapsedTimeInSeconds(startDate: Date) -> TimeInterval {
                return Date().timeIntervalSince(startDate)
            }
    
            func getFormattedElapsedTime(startDate: Date) -> String {
                let elapsed = getElapsedTimeInSeconds(startDate: startDate)
                let totalSeconds = Int(elapsed)
                let hours = totalSeconds / 3600
                let minutes = (totalSeconds % 3600) / 60
                let seconds = totalSeconds % 60
                if hours > 0 {
                    return String(format: "%d:%02d:%02d", hours, minutes, seconds)
                } else {
                    return String(format: "%d:%02d", minutes, seconds)
                }
            }
    
            func getFutureDate() -> Date {
                return Date().addingTimeInterval(365 * 24 * 60 * 60)
            }
        }
    
        // Static content that doesn't change during the activity
        var taskId: String
        var startDate: Date
        var endDate: Date
        var countsDown: Bool // true for timer mode
    }
    
     @ViewBuilder
        func lockScreenView(context: ActivityViewContext) -> some View {
            HStack {
                // Left side - Icon and timer
                VStack(alignment: .leading, spacing: 4) {
                    HStack(spacing: 8) {
                        Image(systemName: "timer")
                            .foregroundColor(Color(hex: context.state.taskColor) ?? .orange)
                            .font(.title3)
    
                        if isTimerCompleted(context: context) {
                            Text("Done!")
                                .font(.system(size: 16, weight: .semibold))
                                .foregroundColor(.green)
                        } else if context.state.isPaused {
                            Text("Paused")
                                .font(.system(size: 16, weight: .semibold))
                                .foregroundColor(Color(hex: context.state.taskColor) ?? .orange)
                        } else {
                            Text(timerInterval: Date()...context.attributes.endDate, countsDown: true)
                                .font(.system(size: 16, weight: .semibold))
                                .foregroundColor(Color(hex: context.state.taskColor) ?? .orange)
                                .monospacedDigit()
                        }
                    }
    
                    Text(context.state.isPaused ? "Timer Paused" : "Timer Active")
                        .font(.caption)
                        .foregroundColor(.secondary)
                }
    
                Spacer()
    
                // Right side - Task title
                VStack(alignment: .trailing, spacing: 4) {
                    Text(context.state.taskTitle)
                        .font(.headline)
                        .fontWeight(.semibold)
                        .multilineTextAlignment(.trailing)
                        .lineLimit(2)
                        .foregroundColor(.white)
    
                    Text("\(Int(calculateProgress(attributes: context.attributes, state: context.state) * 100))% Complete")
                        .font(.caption)
                        .foregroundColor(.secondary)
                }
            }
            .padding(16)
        }
    



    Source link

    iOS issue layout LiveActivity Timer
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    ios – Apple mapkit route function dose not works in China

    October 12, 2025

    swift – Does UIDevice.current.identifierForVendor change after iCloud backup and restore on another iOS device?

    October 11, 2025

    uitabbarcontroller – How to add custom UIView to floating UITabBarItem in iOS 26 Liquid Glass UITabBar

    October 10, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Tailoring nanoscale interfaces for perovskite–perovskite–silicon triple-junction solar cells

    October 13, 2025

    SGLA criticizes California Governor Newsom for signing ‘flawed, rushed’ sweepstakes ban

    October 13, 2025

    Gesture Recognition for Busy Hands

    October 13, 2025

    Inside the ‘Let’s Break It Down’ Series for Network Newbies

    October 13, 2025
    Advertisement
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Tailoring nanoscale interfaces for perovskite–perovskite–silicon triple-junction solar cells

    October 13, 2025

    SGLA criticizes California Governor Newsom for signing ‘flawed, rushed’ sweepstakes ban

    October 13, 2025

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2025 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.