Back to AtesKit
UI Components

Picker Components

AtesKit provides SwiftUI-friendly image picker components with automatic camera fallback, editing support, and ready-to-use button wrappers.

Key Features

SwiftUI Integration: UIViewControllerRepresentable for seamless SwiftUI usage
Smart Fallback: Automatic photo library fallback when camera unavailable
Built-in Editing: Image editing enabled by default
Ready-to-Use: High-level wrapper with built-in button and preview

AKImagePicker

A UIViewControllerRepresentable wrapper for UIImagePickerController with automatic camera/photo library fallback and editing support.
USE CASES
Profile picture selection
Photo uploads
Camera capture
Image editing workflows
User-generated content
FEATURES
Automatic camera availability check
Photo library fallback
Built-in image editing
Completion callback support
SwiftUI integration via UIViewControllerRepresentable
PARAMETERS
isPresented
Binding<Bool>
Controls the presentation state of the picker
selectedImage
Binding<UIImage>
Binding to store the selected/edited image
onImageSelectionCompleted
((UIImage) -> Void)?
Default: nil
Optional callback when image selection completes
sourceType
UIImagePickerController.SourceType
Source type: .camera or .photoLibrary (auto-fallback to library if camera unavailable)
USAGE EXAMPLES
Swift
@State private var showPicker = false
@State private var selectedImage = UIImage()

Button("Select Photo") {
    showPicker = true
}
.sheet(isPresented: $showPicker) {
    AKImagePicker(
        isPresented: $showPicker,
        selectedImage: $selectedImage,
        onImageSelectionCompleted: { image in
            print("Image selected: \(image.size)")
            // Process the image
        },
        sourceType: .camera // Falls back to .photoLibrary if camera unavailable
    )
}

// Display selected image
if selectedImage != UIImage() {
    Image(uiImage: selectedImage)
        .resizable()
        .scaledToFit()
        .frame(height: 200)
}

AKImagePickerView

A high-level, ready-to-use image picker button with built-in preview. Wraps AKImagePicker for simplified usage with custom placeholder content.
USE CASES
Profile picture buttons
Avatar selectors
Quick photo uploads
Image placeholder replacements
Form image fields
FEATURES
Built-in button wrapper
Automatic image preview
Custom placeholder content
Initial image support
Automatic sheet presentation
GeometryReader-based sizing
PARAMETERS
initialImage
Data?
Default: nil
Optional initial image data to display
onImageSelectionCompleted
((UIImage) -> Void)?
Default: nil
Callback when user selects an image
content
@ViewBuilder () -> Content
Custom placeholder view shown when no image is selected
USAGE EXAMPLES
Swift
// Simple usage with icon placeholder
AKImagePickerView { image in
    print("New image selected")
    saveImage(image)
} content: {
    VStack {
        Image(systemName: "person.circle.fill")
            .font(.system(size: 80))
            .foregroundColor(.gray)
        Text("Tap to select photo")
            .font(.caption)
    }
}
.frame(width: 120, height: 120)
.clipShape(Circle())

// With initial image
AKImagePickerView(initialImage: userData.profileImageData) { image in
    userData.updateProfilePicture(image)
} content: {
    ZStack {
        Color.gray.opacity(0.2)
        VStack {
            Icon(systemName: "camera.fill")
            Text("Add Photo")
        }
    }
}
.frame(width: 200, height: 200)
.cornerRadius(12)

// Inline in a form
Form {
    Section("Profile") {
        HStack {
            Text("Avatar")
            Spacer()
            AKImagePickerView { image in
                viewModel.avatar = image
            } content: {
                Image(systemName: "photo")
                    .foregroundColor(.blue)
            }
            .frame(width: 60, height: 60)
            .clipShape(RoundedRectangle(cornerRadius: 8))
        }
    }
}

Best Practices

Permissions: Add camera and photo library usage descriptions to Info.plist
Error Handling: Check camera availability before setting sourceType to .camera
Image Processing: Use completion callback for async image processing/upload
Memory: Resize large images before storing to prevent memory issues

Required Info.plist Keys

Add these privacy descriptions to your Info.plist for camera and photo library access:
Info.plist
<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>We need photo library access to select images</string>