<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zain Haider on Medium]]></title>
        <description><![CDATA[Stories by Zain Haider on Medium]]></description>
        <link>https://medium.com/@developerzain?source=rss-400c2e315b7f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WYoMOHtxO__U9Ut-</url>
            <title>Stories by Zain Haider on Medium</title>
            <link>https://medium.com/@developerzain?source=rss-400c2e315b7f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:00:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@developerzain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Keyboard Toolbar SwiftUI]]></title>
            <link>https://medium.com/@developerzain/keyboard-toolbar-swiftui-10e7ffe6328e?source=rss-400c2e315b7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/10e7ffe6328e</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[extension-functions]]></category>
            <category><![CDATA[swiftui-animation]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Zain Haider]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 07:08:33 GMT</pubDate>
            <atom:updated>2022-11-28T07:08:33.589Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, in this article I will cover how we can add a toolbar above the keyboard and how we can use this to dismiss the toolbar and show other actions.</p><p>Our final output will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hmTrNqDzGQe8Gvg89Xq9tw.jpeg" /></figure><p>Pros:</p><ul><li>You do not need to use third-party libraries. They can get your sensitive information (i.e keypress) and it can be exploited.</li><li>This is a very light weight extension and easy to use.</li></ul><p>Let’s jump into the code, create a new extension of View:</p><pre>import SwiftUI<br><br>extension View {<br>    func keyboardDismissToolBar(buttonTitle: String = &quot;Done&quot;, dismissed: (()-&gt; Void)? = nil) -&gt; some View {<br>        return toolbar {<br>            ToolbarItem(placement: .keyboard) {<br>                HStack {<br>                    Spacer()<br>                    Button(buttonTitle) {<br>                        //Todo: End Editing Here<br>                        <br>                        //Dismiss Action<br>                        dismissed?()<br>                    }<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>We have created a view extension button 1 button. You can customize this to add more buttons. This extension will accept button title and button action (optional).</p><p>Now create an UIApplication extension and add our keyboard dismiss logic:</p><pre>import UIKit<br><br>extension UIApplication {<br>    func endEditing() {<br>        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)<br>    }<br>}</pre><p>Perfect! Now our extension is ready to be used on any view. you can add this extension to the main screen or main window of the project, which will work throughout the view lifecycle (i.e you can use it on the main vStack):</p><pre>struct ContentView: View {<br>    @State private var text: String = &quot;&quot;<br>    <br>    var body: some View {<br>        VStack {<br>            TextField(&quot;Write a Message...&quot;, text: $text)<br>                .font(.system(size: 16, weight: .regular, design: .default))<br>                .frame(width: 250, height: 44)<br>                .padding([.leading, .trailing])<br>                .background(Color.white)<br>                .cornerRadius(22)<br>        }<br>        .keyboardDismissToolBar()<br>    }<br>}</pre><p><strong>Thank You!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10e7ffe6328e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gamification SwiftUI]]></title>
            <link>https://medium.com/@developerzain/gamification-swiftui-d4d3f9e4f0e6?source=rss-400c2e315b7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4d3f9e4f0e6</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[gamification]]></category>
            <category><![CDATA[viewmodifier]]></category>
            <category><![CDATA[swiftui-animation]]></category>
            <dc:creator><![CDATA[Zain Haider]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 06:31:16 GMT</pubDate>
            <atom:updated>2022-11-28T06:31:16.912Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, in this article I will cover how you can add a gamification bumping effect to any view in SwiftUI.</p><p>We will create a ViewModifier so that we will be able to use ViewModifier for any view.</p><p>Enough talking. Let’s jump to the actual code</p><p>Press Command+N and add a new Swift File and name it ViewPressAction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSBdOlFFcqOZLFS3Qb3BWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2lGUMAZ-jmUV1lq3pUisg.png" /></figure><p>Now let&#39;s create a view modifier:</p><pre>import SwiftUI //1<br><br>struct ButtonPressAction: ViewModifier {<br>    typealias callback = () -&gt; Void //2<br>    <br>    <br>    @State private var isPressed = false // 3<br>    var onRelease: callback? = nil //4<br>    <br>    <br>    func body(content: Content) -&gt; some View {<br>        content<br>            .opacity(isPressed ? 0.6 : 1.0) //5<br>            .scaleEffect(isPressed ? 1.1 : 1.0) //6<br>            .simultaneousGesture( //7<br>                DragGesture(minimumDistance: 0) //8<br>                    .onChanged({ _ in //9<br>                        withAnimation(.easeIn(duration: 0.2)) {<br>                            isPressed = true<br>                        }<br>                    })<br>                    .onEnded({ _ in //10<br>                        withAnimation() {<br>                            isPressed = false<br>                        }<br>                        onRelease?()<br>                    })<br>            )<br>    }<br>}</pre><p>1: Import SwiftUI library</p><p>2: TypeAlias for callback</p><p>3: Declaring state variable to store current last view state</p><p>4: Callback onRelease (the main view can use it as touchUpInside)</p><p>5: Decrease opacity when the view is pressed and restore when the view is released.</p><p>6: Increase scale when the view is pressed to show a bumpy effect</p><p>7: Adding simultaneous gesture which will work parallel to other view gestures.</p><p>8: Adding drag gesture with minimum drag 0</p><p>9: When the gesture is active show a bumpy effect</p><p>10: When the user release view bring the view to normal state.</p><p>Our viewModifier is ready. Now lets create an extenstion of View to make it work with views:</p><pre>extension View {<br>    typealias callback = () -&gt; Void<br>    <br>    func gamificationTouchEvent(onRelease: callback? = nil) -&gt; some View {<br>        modifier(ViewPressAction(onRelease: onRelease))<br>    }<br>}</pre><p>Our ViewPressActionClass will look like this image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7kog39y6Ur1lhs26dLvBLA.png" /></figure><p>Now we can use this modifier on any view just like this:</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    var backGroundColor = Color.blue<br>    var title: String<br>    var titleColor = Color.white<br>    <br>    var body: some View {<br>        HStack {<br>            Rectangle()<br>                .frame(width: 150, height: 150)<br>                .cornerRadius(16)<br>                .foregroundColor(.blue)<br>                .gamificationTouchEvent()<br>            ZStack {<br>                Capsule()<br>                    .frame(width: 150, height: 50)<br>                    .foregroundColor(backGroundColor)<br>                Text(title)<br>                    .foregroundColor(titleColor)<br>            }<br>            .gamificationTouchEvent()<br>            <br>        }<br>    }<br>}<br><br>struct ContentView_Previews: PreviewProvider {<br>    static var previews: some View {<br>        ContentView(title: &quot;Start!&quot;)<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLTa-Go4N0gSP0HfQCPWpw.png" /></figure><p>See working effect:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*bV9MhlY9aNgt1gD0Nuuh_A.gif" /></figure><p><strong>Thank You!</strong> for reading my article. You can download the source code from <a href="https://gist.github.com/ZainMobe/5d2744eb0598d2b1662818e8c1b1db13">here</a>: <a href="https://gist.github.com/ZainMobe/5d2744eb0598d2b1662818e8c1b1db13">https://gist.github.com/ZainMobe/5d2744eb0598d2b1662818e8c1b1db13</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4d3f9e4f0e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>