Skip to content
Read More preview
Rendered from the SwiftUI source on this page.

Read More

From syxUI — written for both platforms, not translated between them.

An inline paragraph with a read-more / read-less toggle.

Accordions · SwiftUI · iOS 17

  • accordion
  • swiftui

The actual source

AccReadMore.swift
// Read More · syxUI · https://syxui.dev/components/acc-read-more
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let accBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Inline read-more text expansion
struct AccReadMore: View {
    @State private var open = false
    var body: some View {
        VStack(alignment: .leading, spacing: 6) {
            Text("About this place").font(.system(size: 16, weight: .semibold))
            Text("Nestled in the heart of the old town, this boutique hotel blends historic charm with modern comfort. Each room is uniquely designed" + (open ? ", featuring locally sourced furniture, rainfall showers and skyline views. Breakfast is served daily on the rooftop terrace." : "…"))
                .font(.system(size: 14)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
            Text(open ? "Read less" : "Read more").font(.system(size: 14, weight: .semibold)).foregroundStyle(accBlue).onTapGesture { open.toggle() }
        }.formaCard().frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17