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

    First mlverse survey results – software, applications, and beyond

    April 27, 2026

    Yong Wang Turns Visualization Into Insights

    April 27, 2026

    OpenAI’s GPT-5.5 in Microsoft Foundry: Frontier intelligence on an enterprise ready platform

    April 27, 2026
    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, 2025013 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

    Delphi + PAServer: How to correctly export iOS app with Notification Service Extension (appex) – missing provisioningProfiles in exportOptions.plist

    April 27, 2026

    ios – Apply shadow only outside of a SwifUI transparent button?

    April 26, 2026

    ios – How to add pictures after keynote update with iPadOS 26.3.1?

    April 25, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    First mlverse survey results – software, applications, and beyond

    April 27, 2026

    Yong Wang Turns Visualization Into Insights

    April 27, 2026

    OpenAI’s GPT-5.5 in Microsoft Foundry: Frontier intelligence on an enterprise ready platform

    April 27, 2026

    Meta’s compute grab continues with agreement to deploy tens of millions of AWS Graviton cores

    April 27, 2026
    Timer Code
    15 Second Timer for Articles
    20
    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!

    First mlverse survey results – software, applications, and beyond

    April 27, 2026

    Yong Wang Turns Visualization Into Insights

    April 27, 2026

    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
      © 2026 bigteetechhub.All Right Reserved

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