Skip to content

phillippbertram/BeamBorder

Repository files navigation

BeamBorder

Swift 5.9+ Platforms License: MIT

BeamBorder is a tiny Swift Package that adds an animated beam border to any SwiftUI view. The repository includes a reusable beamBorder view modifier plus a small iOS demo app with a live configurator.

Animated beam border demo

Installation

Add BeamBorder with Swift Package Manager. In Xcode, choose File → Add Package Dependencies… and enter:

https://github.com/phillippbertram/BeamBorder.git

Or add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/phillippbertram/BeamBorder.git", from: "1.0.0")
]

Then add the library product to your app target and import it where needed:

import BeamBorder
import SwiftUI

BeamBorder uses SwiftUI's KeyframeAnimator and therefore requires iOS 17, macOS 14, tvOS 17, watchOS 10, or visionOS 1 (and newer).

Usage

Text("Ask anything")
    .padding(16)
    .background(.gray.opacity(0.1), in: .rect(cornerRadius: 20))
    .beamBorder()

Customize the border with BeamBorderConfiguration:

let configuration = BeamBorderConfiguration(
    border: .orange,
    showsBaseBorder: true,
    beamColors: [.yellow, .orange, .pink, .purple],
    beamDirection: .inward,
    beamBlur: 18,
    cornerRadius: 20,
    borderLineWidth: 0.6,
    baseBorderLineWidth: 0.8,
    animationDuration: 3
)

Text("Custom beam")
    .padding(16)
    .background(.gray.opacity(0.1), in: .rect(cornerRadius: 20))
    .beamBorder(configuration)

Configuration

BeamBorderConfiguration lets you adjust:

  • border: the animated stroke color.
  • showsBaseBorder: whether a subtle static fallback border is visible.
  • beamColors: the glow colors used by the moving beam.
  • beamDirection: whether the glow bleeds .inward (default), .outward like a halo, or to .both sides of the border. The outward halo renders outside the view's bounds, so clipping ancestors (e.g. clipped() or scroll views) may cut it off.
  • beamBlur: the softness of the glow.
  • cornerRadius: the rounded rectangle radius.
  • borderLineWidth and baseBorderLineWidth: stroke widths.
  • animationDuration: how long one full beam rotation takes.

Beam directions

.inward (default) .outward .both
Inward beam Outward beam Both directions beam

The package also includes small presets:

.beamBorder(.default)
.beamBorder(.visibleBaseBorder)
.beamBorder(.outwardGlow)
.beamBorder(.sunrise)

Example App

Open Examples/BeamBorderExample/BeamBorderExample.xcodeproj to run the included sample app. It imports the local package, shows a compact prompt card, send-state handling, and several SwiftUI previews for light, dark, large Dynamic Type, disabled beam, visible base border, and alternative palette states.

Support

If you find BeamBorder useful, consider buying me a coffee:

Buy Me A Coffee

License

BeamBorder is available under the MIT license. See LICENSE for details.

About

Animated beam border effect for SwiftUI views — configurable colors, blur, and inward/outward glow direction

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages