All posts by StrawberryCode

How to create a Section Background in a UICollectionView in Swift

I recently faced a small challenge on a UICollectionView, the following screenshot illustrates pretty well the situation. In short: I needed to have a transparent background in a UICollectionView to be able to see through some sections, but I didn’t want to be able to see the background in between the cells on some others. Basically, I needed to be able to set different background colors per section. Well, needless to say that functionality doesn’t exist by default on iOS. Luckily for me I found this great article: Changing the section background color in a UICollectionView from Eric Chapman who … Continue reading How to create a Section Background in a UICollectionView in Swift

Be an ecofriendly geek and save the planet: delete your e-mails!

You want to save the planet? Good! Start by cleaning your inbox! Let’s delete some e-mails, shall we? We consume a lot of data every day (e-mails, videos, posts on Facebook, Instagram, Twitter, WhatsApp, DropBox, documents saved in the Cloud, …), and all those data are stored on servers. Basically, the more data we save, the more servers we need (and servers consume electricity). Basic math, nothing new under the sun. What if I told you that we can all do a little bit of good for this planet, just by clicking on one button? Remember those prehistoric e-mails that … Continue reading Be an ecofriendly geek and save the planet: delete your e-mails!

Swift Tips #2: setBorder Extension

Happy New Year! This is my first post of 2016, so I would like to thank you all for reading my blog and to wish you a very Happy New Year. May this year be as bug free as possible in your apps as well as in your life! As a New Year gift, I’d like to share with you a little something that I’m using all the time: my setBorder Extension. It is the first member of my “Extensions essentials”. When I integrate a design or debug something, I want to see quickly where my elements are, so I … Continue reading Swift Tips #2: setBorder Extension

Simple UICollectionView pagination with API and Realm database

If you’re using Realm database and a REST API, you may have encountered a pagination issue at some point. That’s what happened in the project I’m working on. Something was wrong with the pagination and I kept adding variables and ifs until I couldn’t remember what was doing what. Then I realized I needed a clean slate, and I created this little project. So, this is a mockup to test a minimum viable pagination and preloading of data from a REST API to feed a UITableView or UICollectionView, using Realm.io database. Just to make things clear, I am not introducing pagination into … Continue reading Simple UICollectionView pagination with API and Realm database

Swift Tips #1: Extra padding problem on UITextView?

Sometimes when you integrate a design, you need things to be square, everything aligned: buttons, title, images, textView… But wait, what’s that extra padding on the UITextView? You may have tried to print the contentOffset or contentInset without success. That’s not it. However, all your problems can be solved in one line, and here it is: // magic line for a UITextView named textView textView.textContainer.lineFragmentPadding = 0 I wouldn’t call it exactly straight forward, so this is a memo for me and tip for you :)