<?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 José Tony on Medium]]></title>
        <description><![CDATA[Stories by José Tony on Medium]]></description>
        <link>https://medium.com/@_josetony?source=rss-4e7fab38b788------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OsXwDNDlJhDj0g6Eyb0wVQ.jpeg</url>
            <title>Stories by José Tony on Medium</title>
            <link>https://medium.com/@_josetony?source=rss-4e7fab38b788------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:20:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_josetony/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[Constraints don’t have to be bored! (Swift, iOS)]]></title>
            <link>https://medium.com/@_josetony/constraints-dont-have-to-be-bored-swift-ios-1d41496b3965?source=rss-4e7fab38b788------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d41496b3965</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[José Tony]]></dc:creator>
            <pubDate>Wed, 13 Mar 2019 09:58:41 GMT</pubDate>
            <atom:updated>2019-03-13T09:58:41.439Z</atom:updated>
            <content:encoded><![CDATA[<p>Adding constraints is very painful and bored especially for those who like to do it in code (like in my case 😅). So today we’re going to see a new and better (I think) way to do implement constraints in Swift.</p><h3>Nothing more than an extension</h3><p>In order to get this done we just need to add an extension to a base view so all other views have this feature. Let’s see the code:</p><pre><strong>extension</strong> UIView {</pre><pre><strong>func</strong> constraint(left: NSLayoutAnchor&lt;NSLayoutXAxisAnchor&gt;?, top: NSLayoutAnchor&lt;NSLayoutYAxisAnchor&gt;?, right: NSLayoutAnchor&lt;NSLayoutXAxisAnchor&gt;?, bottom: NSLayoutAnchor&lt;NSLayoutYAxisAnchor&gt;?, leftConst: CGFloat = 0, topConst: CGFloat = 0, rightConst: CGFloat = 0, bottomConst: CGFloat = 0) {</pre><pre><strong>    self</strong>.translatesAutoresizingMaskIntoConstraints = <strong>false</strong></pre><pre><strong>    if</strong> <strong>let</strong> l = left {</pre><pre><strong>        self</strong>.leftAnchor.constraint(equalTo: l, constant: leftConst).isActive = <strong>true</strong></pre><pre>    }</pre><pre><strong>    if</strong> <strong>let</strong> t = top {</pre><pre><strong>        self</strong>.topAnchor.constraint(equalTo: t, constant: topConst).isActive = <strong>true</strong></pre><pre>    }</pre><pre><strong>    if</strong> <strong>let</strong> r = right {</pre><pre><strong>        self</strong>.rightAnchor.constraint(equalTo: r, constant: -rightConst).isActive = <strong>true</strong></pre><pre>    }</pre><pre><strong>    if</strong> <strong>let</strong> b = bottom {</pre><pre><strong>        self</strong>.bottomAnchor.constraint(equalTo: b, constant: -bottomConst).isActive = <strong>true</strong></pre><pre>    }</pre><pre>}<br></pre><blockquote>Notice that we’re setting <strong>translatesAutoresizingMaskIntoConstraints</strong> to false so you don’t have do it by yourself no more.</blockquote><h3>And the magic has been done!</h3><p>All we need to do is to add the view to some superView and call the the function to add constraints. Just like this:</p><pre>class SomeVC: UIViewController {</pre><pre>    let someView = MyFancyView()</pre><pre><strong>    override</strong> <strong>func</strong> viewDidLoad() {<br>        <strong>super</strong>.viewDidLoad()</pre><pre>        view.addSubview(someView)<br>        <br>        someView.constraint(left: safeAreaLayoutGuide.leftAnchor,             top: safeAreaLayoutGuide.topAnchor, right: safeAreaLayoutGuide.rightAnchor, bottom: safeAreaLayoutGuide.bottomAnchor)</pre><pre>    }</pre><pre>}</pre><p>And this is pretty much it! Hope It’s helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d41496b3965" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Page Slider with UICollectionView in Swift 4]]></title>
            <link>https://medium.com/@_josetony/page-slider-with-uicollectionview-in-swift-4-172c948128bd?source=rss-4e7fab38b788------2</link>
            <guid isPermaLink="false">https://medium.com/p/172c948128bd</guid>
            <category><![CDATA[slider]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[uicollectionview]]></category>
            <dc:creator><![CDATA[José Tony]]></dc:creator>
            <pubDate>Fri, 14 Dec 2018 15:22:37 GMT</pubDate>
            <atom:updated>2018-12-14T15:22:37.648Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post you are going to learn how to make a Page Slider with UICollectionView. Page Slider is very important to pass some meaningful information about your app and add some style to the app too. Today we’re going to build a Page Slider like this below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKMHguUQQS_c%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKMHguUQQS_c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKMHguUQQS_c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/59beeb9868fbbdbe198f039e776bf3c8/href">https://medium.com/media/59beeb9868fbbdbe198f039e776bf3c8/href</a></iframe><p>All we need to achieve what is on the video is:</p><ol><li>UICollectionViewController</li><li>UICollectionViewDelegateFlowLayout</li></ol><p>Time to code it:</p><ol><li>Create your ViewController class (I’ll name it ViewController, you can name it whatever you want)</li></ol><pre>import UIKit</pre><pre>class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {</pre><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>    }</pre><pre>}</pre><p>2. Create the next and prev buttons as well as pageControl</p><pre>import UIKit</pre><pre>class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {</pre><pre>    let btnNext: UIButton = {<br>        let btn = UIButton(type: .system)<br>        <br>        btn.setTitle(&quot;NEXT&quot;, for: .normal)<br>        btn.setTitleColor(.white, for: .normal)<br>        btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)<br>        btn.translatesAutoresizingMaskIntoConstraints = false<br>        btn.addTarget(self, action: #selector(handleNextPage), for:<br>           .touchUpInside)<br>        btn.tag = 1<br>        <br>        return btn<br>    }()</pre><pre>   let btnPrev: UIButton = {<br>        let btn = UIButton(type: .system)<br>        <br>        btn.setTitle(&quot;PREV&quot;, for: .normal)<br>        btn.setTitleColor(.white, for: .normal)<br>        btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)<br>        btn.translatesAutoresizingMaskIntoConstraints = false<br>        btn.addTarget(self, action: #selector(handleNextPage), for:<br>            .touchUpInside)<br>        btn.tag = 0<br>        <br>        return btn</pre><pre>    }()</pre><pre>    let pageControl: UIPageControl = {<br>        let pc = UIPageControl()<br>        <br>        pc.numberOfPages = 3<br>        pc.currentPage = 0<br>        pc.translatesAutoresizingMaskIntoConstraints = false<br>        <br>        return pc<br>    }()</pre><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>    }</pre><pre>}</pre><p>3. Set UICollectionView settings on viewDidLoad() method</p><pre>collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: &quot;ID&quot;)<br>collectionView.isPagingEnabled = true<br>collectionView.showsHorizontalScrollIndicator = false</pre><p>4. Create a funcion to set views and call it on viewDidLoad() method</p><pre>func setupViews() {<br>        [btnNext, btnPrev, pageControl].forEach {<br>view.addSubview($0) }<br>        <br>        btnNext.heightAnchor.constraint(equalToConstant: 48).isActive = true</pre><pre>        btnNext.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -32).isActive = true</pre><pre>        btnNext.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true<br>        <br>        btnPrev.heightAnchor.constraint(equalToConstant: 48).isActive = true</pre><pre>        btnPrev.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 32).isActive = true</pre><pre>        btnPrev.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true<br>        <br>        pageControl.centerYAnchor.constraint(equalTo: btnNext.centerYAnchor).isActive = true</pre><pre>        pageControl.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true</pre><pre>}</pre><p>5. Implement UICollectionViewController and UICollectionViewDelegateFlowLayout methods</p><pre>override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {<br>        return 3<br>}<br>    <br>override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {<br>        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: &quot;ID&quot;, for: indexPath)<br>        <br>        switch indexPath.item {<br>        case 0:<br>            cell.backgroundColor = .red<br>            break<br>        case 1:<br>            cell.backgroundColor = .purple<br>            break<br>        case 2:<br>            cell.backgroundColor = .brown<br>        default:<br>            cell.backgroundColor = .red<br>        }<br>        <br>        return cell<br>}<br>    <br>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {<br>        return CGSize(width: view.frame.width, height: view.frame.height)<br>}<br>    <br>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {<br>        return 0<br>}</pre><p>6. Now let’s update our pageControll as user swipes</p><pre>override func scrollViewDidScroll(_ scrollView: UIScrollView) {</pre><pre>    let scrollPos = scrollView.contentOffset.x / view.frame.width<br>    pageControl.currentPage = Int(scrollPos)</pre><pre>}</pre><p>7. And finally create a method to change the current page based on the button clicked</p><pre><a href="http://twitter.com/objc">@objc</a> func handleNextPage(button: UIButton) {<br>        <br>        var indexPath: IndexPath!<br>        var current = pageControl.currentPage<br>        <br>        if button.tag == 0 {<br>            current -= 1<br>            if current &lt; 0 {<br>                current = 0<br>            }<br>        } else {<br>            current += 1<br>            if current &gt; 2 {<br>                current = 0<br>            }<br>        }<br>        <br>        indexPath = IndexPath(item: current, section: 0)<br>        <br>        collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)<br>        <br>}</pre><p>8. So now your viewDidLoad() method must look like this for everything work properly</p><pre>override func viewDidLoad() {<br>    super.viewDidLoad()<br>    view.backgroundColor = .white<br>        <br>    collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: &quot;ID&quot;)<br>    collectionView.isPagingEnabled = true<br>    collectionView.showsHorizontalScrollIndicator = false<br>        <br>    setupViews()<br>        <br>}</pre><p>And we’re done, all you have to do is to set scrollDirection as .horizontal via Storyboard or if your are doing by code you can do:</p><pre>let layout = UICollectionViewFlowLayout()<br>layout.scrollDirection = .horizontal</pre><pre>// thats your collectionView<br>let vc = ViewController(collectionViewLayout: layout)</pre><p>That’s pretty much it, I hope it helped you 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=172c948128bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a view shake in swift 4]]></title>
            <link>https://medium.com/@_josetony/how-to-make-a-view-shake-in-swift-4-7d6858bf58d5?source=rss-4e7fab38b788------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d6858bf58d5</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[José Tony]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 15:12:23 GMT</pubDate>
            <atom:updated>2018-12-12T10:38:20.186Z</atom:updated>
            <content:encoded><![CDATA[<p>Animations are very important for a better UX, they let the user know what is happening with the app and the data he is interacting with, today I’m going to cover about shake animation, a very important and common animation used to track user’s attention when something is wrong or needs a certain treatment. So let’s jump up to the code:</p><pre>import UIKit</pre><pre>class Animations {</pre><pre>    static func requireUserAtencion(on onView: UIView) {</pre><pre>        let animation = CABasicAnimation(keyPath: &quot;position&quot;)</pre><pre>        animation.duration = 0.07</pre><pre>        animation.repeatCount = 4</pre><pre>        animation.autoreverses = true</pre><pre>        animation.fromValue = NSValue(cgPoint: CGPoint(x: onView.center.x - 10, y: onView.center.y))</pre><pre>        animation.toValue = NSValue(cgPoint: CGPoint(x: onView.center.x + 10, y: onView.center.y))</pre><pre>        onView.layer.add(animation, forKey: &quot;position&quot;)</pre><pre>    }</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6MMGGl5xitNHKRh_Vod-fg.png" /><figcaption>That’s the actual code</figcaption></figure><p>In the code above we a pretty basic class with the function that does the magic happen. Let’s dive in:</p><ol><li>Create a CABasicAnimation object and pass a keyPath as parameter</li><li>Adding animations properties such as duration, repeatCount, starting and ending value ( you can play with them as you want )</li><li>Finally the animations is add to view you want to animate</li></ol><p>And that’s it, you just have to call:</p><pre>Animations.requireUserAtencion(on: yourView)</pre><p>Hope it helped you! 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d6858bf58d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>