Skip to content
Character Count preview
Rendered from the SwiftUI source on this page.

Character Count

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

A textarea with a live character count.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

CharCountField.swift
// Character Count · syxUI · https://syxui.dev/components/inp-char-count
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

// Textarea with character count
struct CharCountField: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            Text("Share your thoughts about the product…").font(.system(size: 15)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading).padding(14)
            HStack { Spacer(); Text("38 / 280").font(.system(size: 12)).foregroundStyle(.secondary) }.padding(.horizontal, 14).padding(.bottom, 10)
        }.overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).stroke(Color.primary.opacity(0.15), lineWidth: 1)).frame(width: 300)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17