<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SwiftUI Drawing and Animation - AppMakers.Dev</title>
	<atom:link href="https://appmakers.dev/category/swiftui/swiftui-drawing-and-animation/feed/" rel="self" type="application/rss+xml" />
	<link>https://appmakers.dev/category/swiftui/swiftui-drawing-and-animation/</link>
	<description>SwiftUI Tutorials, iOS App Development, SwiftUI, Swift</description>
	<lastBuildDate>Mon, 09 Jun 2025 21:38:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://appmakers.dev/wp-content/uploads/2024/10/cropped-AppMakersDev-32x32.jpg</url>
	<title>SwiftUI Drawing and Animation - AppMakers.Dev</title>
	<link>https://appmakers.dev/category/swiftui/swiftui-drawing-and-animation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Semantic Colors in SwiftUI: accentColor, primary, secondary, custom color</title>
		<link>https://appmakers.dev/semantic-colors-in-swiftui/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Wed, 19 Jun 2024 18:32:42 +0000</pubDate>
				<category><![CDATA[Export Locked]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[SwiftUI Styling and Customization]]></category>
		<category><![CDATA[SwiftUI Tutorials]]></category>
		<guid isPermaLink="false">https://uiexamples.com/?p=567</guid>

					<description><![CDATA[<p>SwiftUI offers a variety of semantic colors that adapt to different contexts and system settings, enhancing the visual consistency and accessibility of your app. Semantic colors automatically adjust to the system&#8217;s color scheme and user preferences, making your app look great in both light and dark modes. This tutorial will guide you through using semantic&#8230;</p>
<p>The post <a href="https://appmakers.dev/semantic-colors-in-swiftui/">Semantic Colors in SwiftUI: accentColor, primary, secondary, custom color</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SwiftUI offers a variety of semantic colors that adapt to different contexts and system settings, enhancing the visual consistency and accessibility of your app. Semantic colors automatically adjust to the system&#8217;s color scheme and user preferences, making your app look great in both light and dark modes. This tutorial will guide you through using semantic colors in SwiftUI with unique and engaging examples.</p>
<h2>Introduction to Semantic Colors</h2>
<p>Semantic colors are predefined colors in SwiftUI that adapt to the app&#8217;s theme and accessibility settings. Some common semantic colors include <code class="" data-line="">accentColor</code>, <code class="" data-line="">primary</code>, and <code class="" data-line="">secondary</code>.</p>
<h3>Example: Using AccentColor</h3>
<p>The <code class="" data-line="">accentColor</code> is a broad theme color applied to views and controls. You can set it at the application level by specifying an accent color in your app’s asset catalog.</p>
<h4>Setting AccentColor in Asset Catalog</h4>
<ol>
<li>Open your asset catalog (Assets.xcassets).</li>
<li>Create a new color set and name it <code class="" data-line="">AccentColor</code>.</li>
<li>Choose your desired color.</li>
</ol>
<h4>Example: Using AccentColor in SwiftUI</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

@main
struct SemanticColorsApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .accentColor(.purple) // Set accent color for the entire app
        }
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            Text(&quot;Accent Color Example&quot;)
                .foregroundStyle(Color.accentColor)
                .padding()
                .background(Color.accentColor.opacity(0.2))
                .cornerRadius(10)
            
            Button(action: {
                print(&quot;Button tapped&quot;)
            }) {
                Text(&quot;Tap Me&quot;)
                    .padding()
                    .background(Color.accentColor)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
        .padding()
    }
}
</code></pre>
<p>In this example, we set the accent color of the entire app to purple using the <code class="" data-line="">accentColor</code> modifier. The <code class="" data-line="">Text</code> and <code class="" data-line="">Button</code>views use the accent color to create a consistent look.</p>
<h3>Example: Using Primary and Secondary Colors</h3>
<p>The <code class="" data-line="">primary</code> and <code class="" data-line="">secondary</code> colors are used for primary and secondary content, respectively. These colors adapt to the system&#8217;s color scheme and user settings.</p>
<h4>Example: Using Primary and Secondary Colors in SwiftUI</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct PrimarySecondaryColorsView: View {
    var body: some View {
        VStack(spacing: 20) {
            Text(&quot;Primary Color Example&quot;)
                .foregroundStyle(Color.primary)
                .padding()
                .background(Color.primary.opacity(0.2))
                .cornerRadius(10)

            Text(&quot;Secondary Color Example&quot;)
                .foregroundStyle(Color.secondary)
                .padding()
                .background(Color.secondary.opacity(0.2))
                .cornerRadius(10)

            Button(action: {
                print(&quot;Primary Button tapped&quot;)
            }) {
                Text(&quot;Primary Button&quot;)
                    .padding()
                    .background(Color.primary)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }

            Button(action: {
                print(&quot;Secondary Button tapped&quot;)
            }) {
                Text(&quot;Secondary Button&quot;)
                    .padding()
                    .background(Color.secondary)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
        .padding()
    }
}

</code></pre>
<p>In this example, we use <code class="" data-line="">Color.primary</code> and <code class="" data-line="">Color.secondary</code> to style text and buttons. These colors adapt to the system&#8217;s light and dark modes, providing a consistent and accessible user experience.</p>
<h3>Example: Customizing System Colors</h3>
<p>In addition to predefined semantic colors, you can customize colors in SwiftUI to create a unique look for your app. Custom colors can be defined in the asset catalog or directly in code.</p>
<h4>Example: Using Custom Colors</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct CustomColorsView: View {
    var body: some View {
        VStack(spacing: 20) {
            Text(&quot;Custom Color Example&quot;)
                .foregroundStyle(Color(&quot;CustomColor&quot;))
                .padding()
                .background(Color(&quot;CustomColor&quot;).opacity(0.2))
                .cornerRadius(10)

            Button(action: {
                print(&quot;Custom Color Button tapped&quot;)
            }) {
                Text(&quot;Custom Color Button&quot;)
                    .padding()
                    .background(Color(&quot;CustomColor&quot;))
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
        .padding()
    }
}

</code></pre>
<p>To use custom colors:</p>
<ol>
<li>Open your asset catalog (Assets.xcassets).</li>
<li>Create a new color set and name it <code class="" data-line="">CustomColor</code>.</li>
<li>Choose your desired color.</li>
</ol>
<p>In this example, we define a custom color in the asset catalog and use it in the <code class="" data-line="">Text</code> and <code class="" data-line="">Button</code> views.</p>
<h2>Conclusion</h2>
<p>Using semantic colors in SwiftUI allows you to create visually consistent and accessible user interfaces. By leveraging <code class="" data-line="">accentColor</code>, <code class="" data-line="">primary</code>, <code class="" data-line="">secondary</code>, and custom colors, you can ensure your app looks great across different themes and user settings.</p>
<p>&nbsp;</p>
<p>The post <a href="https://appmakers.dev/semantic-colors-in-swiftui/">Semantic Colors in SwiftUI: accentColor, primary, secondary, custom color</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Mastering Canvas, GraphicsContext, and Styles in SwiftUI</title>
		<link>https://appmakers.dev/mastering-canvas-graphicscontext-and-styles-in-swiftui/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Tue, 28 May 2024 14:36:58 +0000</pubDate>
				<category><![CDATA[Export Locked]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[SwiftUI Tutorials]]></category>
		<guid isPermaLink="false">https://uiexamples.com/?p=559</guid>

					<description><![CDATA[<p>SwiftUI offers a rich set of tools for creating and customizing user interfaces. Among these are Canvas, GraphicsContext, Border, ForegroundStyle, and BackgroundStyle. This tutorial will guide you through the basics of these powerful features with unique and easy-to-follow examples. Introduction to Canvas Canvas is a view in SwiftUI that provides a drawing area for creating&#8230;</p>
<p>The post <a href="https://appmakers.dev/mastering-canvas-graphicscontext-and-styles-in-swiftui/">Mastering Canvas, GraphicsContext, and Styles in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SwiftUI offers a rich set of tools for creating and customizing user interfaces. Among these are <code class="" data-line="">Canvas</code>, <code class="" data-line="">GraphicsContext</code>, <code class="" data-line="">Border</code>, <code class="" data-line="">ForegroundStyle</code>, and <code class="" data-line="">BackgroundStyle</code>. This tutorial will guide you through the basics of these powerful features with unique and easy-to-follow examples.</p>
<h2>Introduction to Canvas</h2>
<p><code class="" data-line="">Canvas</code> is a view in SwiftUI that provides a drawing area for creating custom graphics. It uses <code class="" data-line="">GraphicsContext</code> to draw shapes, images, and text.</p>
<h3>Example: Drawing with Canvas and GraphicsContext</h3>
<pre><code class="language-swift" data-line="">import SwiftUI

struct CanvasDrawingView: View {
    var body: some View {
        Canvas { context, size in
            context.draw(Text(&quot;Hello, SwiftUI!&quot;), at: CGPoint(x: size.width / 2, y: size.height / 2))
            
            let circle = Path(ellipseIn: CGRect(x: size.width / 4, y: size.height / 4, width: size.width / 2, height: size.height / 2))
            context.fill(circle, with: .color(.blue))
        }
        .frame(width: 300, height: 300)
        .border(Color.black, width: 2)
    }
}
</code></pre>
<p>In this example, we use <code class="" data-line="">Canvas</code> to draw text and a blue circle. The <code class="" data-line="">GraphicsContext</code> allows us to draw shapes and text at specific positions within the canvas.</p>
<h2>Using Border</h2>
<p>The <code class="" data-line="">border</code> modifier adds a border around a view. You can customize the border&#8217;s color, width, and style.</p>
<h3>Example: Applying a Border to a View</h3>
<pre><code class="language-swift" data-line="">struct BorderedView: View {
    var body: some View {
        Text(&quot;Bordered Text&quot;)
            .padding()
            .border(Color.red, width: 4)
    }
}
</code></pre>
<p>In this example, we add a red border around a text view.</p>
<h2>ForegroundStyle</h2>
<p><code class="" data-line="">ForegroundStyle</code> allows you to set the style for the foreground content of a view, such as text or shapes.</p>
<h3>Example: Using ForegroundStyle with Text</h3>
<pre><code class="language-swift" data-line="">struct ForegroundStyledView: View {
    var body: some View {
        Text(&quot;Stylized Text&quot;)
            .font(.largeTitle)
            .foregroundStyle(
                LinearGradient(
                    gradient: Gradient(colors: [.red, .orange]),
                    startPoint: .leading,
                    endPoint: .trailing
                )
            )
            .padding()
    }
}</code></pre>
<p>In this example, we use a linear gradient as the foreground style for the text, creating a smooth color transition.</p>
<h2>BackgroundStyle</h2>
<p><code class="" data-line="">BackgroundStyle</code> allows you to set the background style of a view.</p>
<pre><code class="language-swift" data-line="">struct BackgroundStyledView: View {
    var body: some View {
        Text(&quot;Stylized Background&quot;)
            .padding()
            .background(
                LinearGradient(
                    gradient: Gradient(colors: [.blue, .purple]),
                    startPoint: .top,
                    endPoint: .bottom
                )
            )
            .cornerRadius(10)
            .padding()
    }
}</code></pre>
<p>In this example:</p>
<ol>
<li>We apply a <code class="" data-line="">LinearGradient</code> as the background to a <code class="" data-line="">Text</code> view using the <code class="" data-line="">.background</code> modifier.</li>
<li>The gradient transitions from blue at the top to purple at the bottom.</li>
<li>We add a corner radius to the text view to give it rounded corners.</li>
</ol>
<h2>Conclusion</h2>
<p>SwiftUI&#8217;s <code class="" data-line="">Canvas</code>, <code class="" data-line="">GraphicsContext</code>, <code class="" data-line="">Border</code>, <code class="" data-line="">ForegroundStyle</code>, and <code class="" data-line="">BackgroundStyle</code> provide powerful tools for creating custom graphics and styling views. By understanding and using these features, you can enhance the visual appeal and functionality of your SwiftUI applications.</p>
<p>The post <a href="https://appmakers.dev/mastering-canvas-graphicscontext-and-styles-in-swiftui/">Mastering Canvas, GraphicsContext, and Styles in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Gradients in SwiftUI &#8211; Linear, Radial, Angular</title>
		<link>https://appmakers.dev/gradients-in-swiftui-linear-radial-angular/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Tue, 28 May 2024 12:53:45 +0000</pubDate>
				<category><![CDATA[Export Locked]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[SwiftUI Tutorials]]></category>
		<guid isPermaLink="false">https://uiexamples.com/?p=551</guid>

					<description><![CDATA[<p>Gradients are a powerful tool in SwiftUI that allow you to create visually appealing backgrounds and effects. SwiftUI supports several types of gradients, including linear, radial, and angular gradients. This tutorial will guide you through the basics of using gradients in SwiftUI, with unique and interesting examples that are simple to understand for developers of&#8230;</p>
<p>The post <a href="https://appmakers.dev/gradients-in-swiftui-linear-radial-angular/">Gradients in SwiftUI &#8211; Linear, Radial, Angular</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Gradients are a powerful tool in SwiftUI that allow you to create visually appealing backgrounds and effects. SwiftUI supports several types of gradients, including linear, radial, and angular gradients. This tutorial will guide you through the basics of using gradients in SwiftUI, with unique and interesting examples that are simple to understand for developers of all levels.</p>
<h2>Introduction to Gradients in SwiftUI</h2>
<p>SwiftUI provides built-in support for creating gradients using the <code class="" data-line="">LinearGradient</code>, <code class="" data-line="">RadialGradient</code>, and <code class="" data-line="">AngularGradient</code> views. These gradients can be used to fill shapes, backgrounds, and more.</p>
<h3>Linear Gradient</h3>
<p>A linear gradient creates a color transition along a straight line. You can define the start and end points, as well as the colors to transition between.</p>
<h4>Example: Creating a Linear Gradient</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct LinearGradientView: View {
    var body: some View {
        Rectangle()
            .fill(
                LinearGradient(
                    gradient: Gradient(colors: [Color.red, Color.blue]),
                    startPoint: .topLeading,
                    endPoint: .bottomTrailing
                )
            )
            .frame(width: 200, height: 200)
    }
}
</code></pre>
<p>In this example, we create a <code class="" data-line="">Rectangle</code> filled with a linear gradient that transitions from red to blue, starting from the top leading corner to the bottom trailing corner.</p>
<h3>Radial Gradient</h3>
<p>A radial gradient creates a color transition radiating outward from a center point.</p>
<h4>Example: Creating a Radial Gradient</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct RadialGradientView: View {
    var body: some View {
        Circle()
            .fill(
                RadialGradient(
                    gradient: Gradient(colors: [Color.yellow, Color.orange]),
                    center: .center,
                    startRadius: 20,
                    endRadius: 100
                )
            )
            .frame(width: 200, height: 200)
    }
}</code></pre>
<p>In this example, we create a <code class="" data-line="">Circle</code> filled with a radial gradient that transitions from yellow at the center to orange at the edges.</p>
<h3>Angular Gradient</h3>
<p>An angular gradient creates a color transition around a circle, sweeping from one color to another.</p>
<h4>Example: Creating an Angular Gradient</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct AngularGradientView: View {
    var body: some View {
        Circle()
            .fill(
                AngularGradient(
                    gradient: Gradient(colors: [Color.purple, Color.pink, Color.purple]),
                    center: .center
                )
            )
            .frame(width: 200, height: 200)
    }
}</code></pre>
<p>In this example, we create a <code class="" data-line="">Circle</code> filled with an angular gradient that transitions from purple to pink and back to purple around the center.</p>
<h3>Using EllipticalGradient with Shapes</h3>
<p>Elliptical gradients can be applied to various shapes, not just ellipses. You can use them with rectangles, circles, and custom shapes to create unique visual effects.</p>
<h4>Example: Applying Elliptical Gradient to a Rectangle</h4>
<pre><code class="language-swift" data-line="">import SwiftUI

struct EllipticalGradientRectangleView: View {
    var body: some View {
        Rectangle()
            .fill(
                EllipticalGradient(
                    gradient: Gradient(colors: [.green, .yellow]),
                    center: .center,
                    startRadiusFraction: 0.2,
                    endRadiusFraction: 0.8
                )
            )
            .frame(width: 300, height: 200)
    }
}
</code></pre>
<h3>Combining Gradients</h3>
<p>You can combine different gradients to create more complex and interesting effects.</p>
<h4>Example: Combining Linear and Radial Gradients</h4>
<pre><code class="language-swift" data-line="">struct CombinedGradientView: View {
    var body: some View {
        ZStack {
            Rectangle()
                .fill(
                    LinearGradient(
                        gradient: Gradient(colors: [Color.blue.opacity(0.5), Color.green.opacity(0.5)]),
                        startPoint: .top,
                        endPoint: .bottom
                    )
                )
                .frame(width: 300, height: 300)
            
            Circle()
                .fill(
                    RadialGradient(
                        gradient: Gradient(colors: [Color.white.opacity(0.5), Color.clear]),
                        center: .center,
                        startRadius: 50,
                        endRadius: 150
                    )
                )
                .frame(width: 300, height: 300)
        }
    }
}</code></pre>
<p>In this example, we create a <code class="" data-line="">Rectangle</code> with a linear gradient background and overlay a <code class="" data-line="">Circle</code> with a radial gradient to create a more complex visual effect.</p>
<h2>Conclusion</h2>
<p>Gradients are a versatile tool in SwiftUI that can enhance the visual appeal of your app. By understanding how to use <code class="" data-line="">LinearGradient</code>, <code class="" data-line="">RadialGradient</code>, and <code class="" data-line="">AngularGradient</code>, you can create stunning effects and backgrounds.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://appmakers.dev/gradients-in-swiftui-linear-radial-angular/">Gradients in SwiftUI &#8211; Linear, Radial, Angular</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>AsyncImage in SwiftUI</title>
		<link>https://appmakers.dev/asyncimage-in-swiftui/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Thu, 23 May 2024 12:52:48 +0000</pubDate>
				<category><![CDATA[Export Locked]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[SwiftUI Tutorials]]></category>
		<category><![CDATA[SwiftUI Views]]></category>
		<guid isPermaLink="false">https://uiexamples.com/?p=536</guid>

					<description><![CDATA[<p>SwiftUI&#8217;s AsyncImage view simplifies the process of loading and displaying remote images asynchronously. It provides built-in support for placeholders and error handling, making it an essential tool for modern app development. This tutorial will guide you through the basics and demonstrate unique examples that cater to developers of all levels. Introduction to AsyncImage AsyncImage is&#8230;</p>
<p>The post <a href="https://appmakers.dev/asyncimage-in-swiftui/">AsyncImage in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SwiftUI&#8217;s <code class="" data-line="">AsyncImage</code> view simplifies the process of loading and displaying remote images asynchronously. It provides built-in support for placeholders and error handling, making it an essential tool for modern app development. This tutorial will guide you through the basics and demonstrate unique examples that cater to developers of all levels.</p>
<h3>Introduction to AsyncImage</h3>
<p><code class="" data-line="">AsyncImage</code> is a view that asynchronously loads and displays an image from a specified URL. You can easily add a placeholder, handle errors, and manipulate the loaded image.</p>
<h3>Basic Usage of AsyncImage</h3>
<p>Let&#8217;s start with a basic example of loading an image from a URL and displaying it in a SwiftUI view.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct BasicAsyncImageView: View {
    let imageUrl = URL(string: &quot;https://picsum.photos/200&quot;)

    var body: some View {
        AsyncImage(url: imageUrl)
            .frame(width: 200, height: 200)
    }
}</code></pre>
<p>In this example, we load an image from a URL and display it within a 200&#215;200 frame. Until the image loads, SwiftUI displays a default placeholder.</p>
<h3>Customizing the Placeholder</h3>
<p>You can customize the placeholder to enhance the user experience while the image is loading.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct PlaceholderAsyncImageView: View {
    let imageUrl = URL(string: &quot;https://picsum.photos/200&quot;)

    var body: some View {
        AsyncImage(url: imageUrl) { image in
            image
                .resizable()
                .aspectRatio(contentMode: .fit)
        } placeholder: {
            ProgressView(&quot;Loading...&quot;)
                .frame(width: 200, height: 200)
        }
    }
}
</code></pre>
<p>Here, we use <code class="" data-line="">ProgressView</code> as a custom placeholder, which is displayed until the image is fully loaded.</p>
<h3>Handling Errors</h3>
<p>It&#8217;s crucial to handle errors gracefully, providing a fallback UI when the image fails to load.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ErrorHandlingAsyncImageView: View {
    let imageUrl = URL(string: &quot;https://picsum.photos/200&quot;)

    var body: some View {
        AsyncImage(url: imageUrl) { phase in
            switch phase {
            case .empty:
                ProgressView(&quot;Loading...&quot;)
                    .frame(width: 200, height: 200)
            case .success(let image):
                image
                    .resizable()
                    .aspectRatio(contentMode: .fit)
            case .failure:
                Image(systemName: &quot;exclamationmark.triangle&quot;)
                    .resizable()
                    .frame(width: 50, height: 50)
                    .foregroundColor(.red)
            @unknown default:
                EmptyView()
            }
        }
        .frame(width: 200, height: 200)
    }
}</code></pre>
<p>In this example, we handle different loading phases using a switch statement. If the image fails to load, we display a system symbol as an error indicator.</p>
<h3>Advanced Example: Image Grid</h3>
<p>Let&#8217;s create an advanced example where we display a grid of asynchronously loaded images.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ImageGridAsyncView: View {
    let urls = [
        URL(string: &quot;https://picsum.photos/200/300&quot;),
        URL(string: &quot;https://picsum.photos/200&quot;),
        URL(string: &quot;https://picsum.photos/300&quot;),
        URL(string: &quot;https://picsum.photos/400&quot;)
    ]

    var body: some View {
        let columns = [
            GridItem(.flexible()),
            GridItem(.flexible())
        ]
        
        ScrollView {
            LazyVGrid(columns: columns, spacing: 20) {
                ForEach(urls, id: \.self) { url in
                    AsyncImage(url: url) { phase in
                        switch phase {
                        case .empty:
                            ProgressView()
                                .frame(width: 100, height: 100)
                        case .success(let image):
                            image
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: 100, height: 100)
                                .clipped()
                        case .failure:
                            Image(systemName: &quot;exclamationmark.triangle&quot;)
                                .resizable()
                                .frame(width: 50, height: 50)
                                .foregroundColor(.red)
                        @unknown default:
                            EmptyView()
                        }
                    }
                }
            }
            .padding()
        }
    }
}</code></pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://appmakers.dev/asyncimage-in-swiftui/">AsyncImage in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Image in SwiftUI</title>
		<link>https://appmakers.dev/image-in-swiftui/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Tue, 21 May 2024 12:21:58 +0000</pubDate>
				<category><![CDATA[Export Locked]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[SwiftUI Tutorials]]></category>
		<category><![CDATA[SwiftUI Views]]></category>
		<guid isPermaLink="false">https://uiexamples.com/?p=531</guid>

					<description><![CDATA[<p>SwiftUI provides an easy way for adding and manipulating images in your apps. This tutorial will guide you through the basics of using images in SwiftUI, with unique and interesting examples that cater to developers of all levels. Introduction to Image in SwiftUI The Image view in SwiftUI displays an image and provides various initializers&#8230;</p>
<p>The post <a href="https://appmakers.dev/image-in-swiftui/">Image in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SwiftUI provides an easy way for adding and manipulating images in your apps. This tutorial will guide you through the basics of using images in SwiftUI, with unique and interesting examples that cater to developers of all levels.</p>
<h2>Introduction to Image in SwiftUI</h2>
<p>The <code class="" data-line="">Image</code> view in SwiftUI displays an image and provides various initializers and modifiers to customize its appearance. You can create images from different sources, such as asset catalogs, <code class="" data-line="">UIImage</code> or <code class="" data-line="">NSImage</code> instances, and SF Symbols.</p>
<h3>Creating a Basic Image</h3>
<p>Let&#8217;s start with a simple example of displaying an image from the app’s asset library.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ContentView: View {
    var body: some View {
        Image(&quot;exampleImage&quot;) // Replace &quot;exampleImage&quot; with your image name
            .resizable()
            .aspectRatio(contentMode: .fit)
            .padding()
    }
}
</code></pre>
<p>In this example, the image is loaded from the asset catalog, made resizable, and its aspect ratio is maintained to fit within its container.</p>
<h2>Customizing Image Views</h2>
<p>SwiftUI provides several modifiers to customize how images are displayed. Here are some useful modifiers and how to use them:</p>
<h3>Resizing and Scaling Images</h3>
<p>You can resize and scale images to fit or fill a given space while maintaining their aspect ratio.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ResizableImageView: View {
    var body: some View {
        VStack {
            Image(&quot;exampleImage&quot;)
                .resizable()
                .scaledToFit()
                .frame(width: 200, height: 200)
                .border(Color.green, width: 1)
            
            Image(&quot;exampleImage&quot;)
                .resizable()
                .scaledToFill()
                .frame(width: 300, height: 200)
                .clipped()
                .border(Color.gray, width: 10)
        }
    }
}
</code></pre>
<h3>Applying Shapes and Borders</h3>
<p>You can apply various shapes and borders to your images to make them more visually appealing.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ShapedImageView: View {
    var body: some View {
        VStack {
            Image(&quot;exampleImage&quot;)
                .resizable()
                .clipShape(Circle())
                .overlay(Circle().stroke(Color.white, lineWidth: 4))
                .shadow(radius: 10)
                .padding()

            Image(&quot;exampleImage&quot;)
                .resizable()
                .clipShape(RoundedRectangle(cornerRadius: 25))
                .overlay(RoundedRectangle(cornerRadius: 25).stroke(Color.white, lineWidth: 4))
                .shadow(radius: 10)
                .padding()
        }
    }
}
</code></pre>
<h3>Applying Color Adjustments to Image in SwiftUI</h3>
<pre><code class="language-swift" data-line="">import SwiftUI

struct ColorAdjustmentImageView: View {
    var body: some View {
        VStack {
            Image(&quot;exampleImage&quot;)
                .resizable()
                .scaledToFit()
                .brightness(0.2) // Increases the brightness of the image
                .contrast(1.5) // Increases the contrast of the image
                .saturation(1.2) // Increases the saturation of the image
                .frame(width: 300, height: 200)
                .padding()
        }
    }
}
</code></pre>
<h3>Applying Blend Mode</h3>
<p>The <code class="" data-line="">blendMode</code> modifier allows you to apply different blending effects to images, combining them with their background or other views.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct BlendModeImageView: View {
    var body: some View {
        VStack {
            Image(&quot;exampleImage&quot;)
                .resizable()
                .scaledToFit()
                .blendMode(.multiply) // Applies multiply blend mode to the image
                .frame(width: 300, height: 200)
                .background(Color.yellow) // Background color to blend with the image
                .padding()
        }
    }
}
</code></pre>
<h3>Rotating and Scaling Images</h3>
<p>You can use the <code class="" data-line="">rotationEffect</code> and <code class="" data-line="">scaleEffect</code> modifiers to rotate and scale images in SwiftUI.</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct RotateAndScaleImageView: View {
    var body: some View {
        VStack {
            Image(&quot;exampleImage&quot;)
                .resizable()
                .scaledToFit()
                .rotationEffect(.degrees(45)) // Rotates the image by 45 degrees
                .scaleEffect(1.5) // Scales the image by 1.5 times
                .frame(width: 300, height: 200)
                .padding()
        }
    }
}
</code></pre>
<h3>Using SF Symbols</h3>
<p>SF Symbols are a set of over 2,400 configurable symbols that you can use in your SwiftUI apps. Here&#8217;s how to use them:</p>
<pre><code class="language-swift" data-line="">import SwiftUI

struct SFSymbolsView: View {
    var body: some View {
        VStack {
            Image(systemName: &quot;star.fill&quot;)
                .font(.largeTitle)
                .foregroundColor(.yellow)
            
            Image(systemName: &quot;heart.fill&quot;)
                .font(.system(size: 50))
                .foregroundColor(.red)
        }
    }
}
</code></pre>
<h3>Creating a Custom Image with Drawing Instructions</h3>
<p>SwiftUI also allows you to create custom images using drawing instructions. Here’s a simple example:</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre><code class="language-swift" data-line="">import SwiftUI

struct CustomDrawingImageView: View {
    var body: some View {
        Image(uiImage: drawCustomImage())
            .resizable()
            .scaledToFit()
            .frame(width: 200, height: 200)
    }
    
    func drawCustomImage() -&gt; UIImage {
        let renderer = UIGraphicsImageRenderer(size: CGSize(width: 200, height: 200))
        return renderer.image { context in
            let cgContext = context.cgContext
            cgContext.setFillColor(UIColor.blue.cgColor)
            cgContext.fill(CGRect(x: 0, y: 0, width: 200, height: 200))
            cgContext.setFillColor(UIColor.white.cgColor)
            cgContext.setStrokeColor(UIColor.red.cgColor)
            cgContext.setLineWidth(10)
            cgContext.addEllipse(in: CGRect(x: 50, y: 50, width: 100, height: 100))
            cgContext.drawPath(using: .fillStroke)
        }
    }
}
</code></pre>
</div>
</div>
<div>
<h2>Conclusion</h2>
<p>SwiftUI’s <code class="" data-line="">Image</code> view is a versatile and powerful tool for displaying and customizing images in your apps. By using various initializers and modifiers, you can create a wide range of image views that are responsive, visually appealing, and accessible.</p>
</div>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center"></div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://appmakers.dev/image-in-swiftui/">Image in SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Color &#8211; SwiftUI</title>
		<link>https://appmakers.dev/color-swiftui/</link>
		
		<dc:creator><![CDATA[AppMakers]]></dc:creator>
		<pubDate>Mon, 02 Dec 2019 09:42:42 +0000</pubDate>
				<category><![CDATA[iOS Development]]></category>
		<category><![CDATA[SwiftUI]]></category>
		<category><![CDATA[SwiftUI Drawing and Animation]]></category>
		<category><![CDATA[Color]]></category>
		<guid isPermaLink="false">https://appmakers.dev/?p=1086</guid>

					<description><![CDATA[<p>Color in SwiftUI is an environment-dependent color. How to change the background color of the view in SwiftUI This will set the background of the Text to .red var body: some View { Text(&#34;Hello AppMakers.dev visitors&#34;) .background(Color.red) } If you want to set the whole screen to be red, you can do this. This will&#8230;</p>
<p>The post <a href="https://appmakers.dev/color-swiftui/">Color &#8211; SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Color in SwiftUI is an environment-dependent color.</p>
<h2>How to change the background color of the view in SwiftUI</h2>
<p>This will set the background of the Text to .red</p>
<pre><code class="language-swift" data-line="">var body: some View {
    Text(&quot;Hello AppMakers.dev visitors&quot;)
        .background(Color.red)
}</code></pre>
<p>If you want to set the whole screen to be red, you can do this. This will center the text and set the whole view to red.</p>
<pre><code class="language-swift" data-line="">var body: some View {
    HStack {
        Spacer()
        VStack {
            Spacer()
            Text(&quot;Hello AppMakers.dev&quot;)
            Spacer()
        }
        Spacer()
    }
    .background(Color.red)
}</code></pre>
<p>Or use this instead to fill the whole view with red, ignoring the safe area.</p>
<pre><code class="language-swift" data-line="">var body: some View {
    ZStack {
        Color.red
            .edgesIgnoringSafeArea(.all)
        Text(&quot;Hello AppMakers.Dev&quot;)
    }
}</code></pre>
<h2>How to change Text Color in SwiftUI</h2>
<p>This code will change the text color to green. Use `foregroundColor(_:)` to set the color that the view uses for foreground elements.</p>
<pre><code class="language-swift" data-line="">var body: some View {
    Text(&quot;Hello&quot;)
        .foregroundColor(Color.green)
}</code></pre>
<h2>How to convert UIColor to SwiftUI Color</h2>
<p>To convert UIColor to SwiftUI Color, add this extension to your codebase.</p>
<pre><code class="language-swift" data-line="">extension UIColor {
    var suColor: Color { Color(self) }
}</code></pre>
<p>After that, you can call `.suColor` on any `UIColor` instance to get a SwiftUI Color.</p>
<pre><code class="language-swift" data-line="">someUIColor.suColor</code></pre>
<h2>How to use Color set from Assets Catalog?</h2>
<p>If you&#8217;ve created a color named &#8220;newColor&#8221; in your Assets catalog, you can use it like this:</p>
<pre><code class="language-swift" data-line="">Color(&quot;newColor&quot;)</code></pre>
<p>To simplify usage of Asset Catalog colors, add this extension:</p>
<pre><code class="language-swift" data-line="">extension Color {
    static let newColor = Color(&quot;newColor&quot;)
    static let newColor2 = Color(&quot;newColor2&quot;)
}</code></pre>
<p>Learn more about SwiftUI using <a href="https://appmakers.dev/swiftui-tutorials/">SwiftUI Tutorials</a> by AppMakers. You can always check the official documentation if updates occur.</p>
<p><a href="https://developer.apple.com/documentation/swiftui/color" target="_blank" rel="noopener noreferrer">Color Documentation</a></p>
<p>The post <a href="https://appmakers.dev/color-swiftui/">Color &#8211; SwiftUI</a> appeared first on <a href="https://appmakers.dev">AppMakers.Dev</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
