:  ~ 4 min read

Increasing the tap area of a UIButton

The other day, Soroush wrote a great post about hitTest(_:with:) (you should check it out), which reminded me of a problem I solved the other week: I wanted to increase a UIButton’s tap area, without increasing the button’s frame.

The following code would go in one of the button’s superviews; for example, you might have a mainContainer, which has a UIStackView that contains the button — we’d implement it in mainContainer:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
	let biggerButtonFrame = theButton.frame.insetBy(dx: -30, dy: -30) // 1
		
	if biggerButtonFrame.con […]

Continue reading →

:  ~ 3 min read

Extracting the location from a photo

In this post I’d like to explain how to let the user pick a photo and automatically extract the location for them. The post is targeted at iOS 11+, because starting with this version, to use an UIImagePickerController we don’t need to ask the user’s permission to access their photo library, because the controller runs as a separate process from the app, which means the app gets read-only access only to the image the user selected, and just to the image — no metadata included.

For this, we will need the UIImagePickerController:

func pickPhotoFromLibrary() {
	// 1
	guard UIImagePickerController.isSou […]

Continue reading →

:  ~ 6 min read

Extracting and parsing tweets from your Twitter archive

I’ve recently gave Micro.blog a try and  shortly after  I thought of importing all my tweets here, because … why not own my content? This post will be about extracting and converting your Twitter archive into simpler objects with just text and timestamp — there are many more available fields, but these were the only ones I was particularly interested in.

First things first, we need to request your archive: in our Twitter’s profile settings, all the way to the bottom we can find ”Your Tweet archive”; we need to click on ”Request your archive” and after a while we’ll receive an email with a link […]


Continue reading →

:  ~ 1 min read

UITextView and UITextField knobs; a story

UIKit does this really nice thing, where the user can tap around a text knob — with quite some margin, too — and still intercept the touch; but it appears that all knobs are created equal, but some are more equal than others; and so our story begins…

On one of our projects, the view for creating a challenge is full of UITextViews — almost all of them can have two rows or more, so we couldn’t use UITextFields. The default textContainerInsets were too big — at least vertically — so they were set to 0, at which point a problem arose: the knobs were cut off; and not only that, they weren’t interce […]


Continue reading →

:  ~ 1 min read

Card Virtual

A few months ago I was writing about a new beginning and I mentioned a couple of projects. I mentioned first one in a previous post and now I'm writing about the second.

The main goal of the app is for users to save their fidelity cards digitally (or request new ones), combined with the conveniences of displaying merchants & their offers, and having a shopping list at hand. There's also a friends feature, with which users can share their shopping lists — shopping together, faster and smarter has never been easier!

It's targeted at the local, Romanian, market, but it should be possible to adapt […]


Continue reading →

:  ~ 45 sec read

Tower

2 years and a half ago, I was writing about how I recently started using Tower — didn't even realize it's been so long. In that post I was explaining how I solved the fact that it doesn't support opening Pull Requests. Well ... The latest version of Tower now supports it, and I gotta say they're as seamless as one would expect!

A few new features:

 […]
Continue reading →

:  ~ 3 min read

Observing and broadcasting

The usual solution to observe and broadcast is to use NotificationCenter:

final class Post { // 1

  	var title: String
	var body: String

	init(title: String, body: String) {
		self.title = title
		self.body = body
	}

}

extension NSNotification.Name { // 2

	static let LTHPostReceived = NSNotification.Name(rawValue: "com.rolandleth.com.postReceivedNotification")

}

final class PostCreationController: UIViewController { // 3

	private let post: Post

	// [...]

	private func savePost() { // 4
		// [...]

		let userInfo = ["post": post] // 5
		let notification = Notification(name: .LTHPostReceiv […]

Continue reading →

:  ~ 2 min read

ChallengeBeat

A few months ago I was writing about a new beginning and I mentioned a couple of projects. I would like to present one of them today. It took longer than expected, but we launched today and we're really happy about the results. I'll start with a really short intro:

Our lives are filled with habits; some are good, some are bad. Everyone wants to get rid of their bad habits, and we all want to increase the number and/or frequency of good habits; we all want to eat healthier, do more sport, be more productive, or procrastinate less.

On the other hand, we humans are, by nature, a really sociable s […]


Continue reading →

:  ~ 1 min read

Easier NSLayoutConstraint interactions #2

In a previous post I talked about a new struct (LayoutPriority) and a couple of extension methods on NSLayoutConstraint to ease interacting with them. But, as I later discovered, there is no need for the new struct – we can do the same thing on UILayoutPriority itself. Let's quickly see how.

First, we move all the properties along with the operators to the extension:

extension UILayoutPriority {
	
	static let minNonZero = UILayoutPriority(rawValue: 1)
	static let belowDefaultLow = UILayoutPriority(rawValue: UILayoutPriority.defaultLow.rawValue - 1)
	static let defaultLow = UILayoutPriority(raw […]

Continue reading →

:  ~ 5 min read

Creating an interactive label

I would like to write about how you can create a label that detects and responds to various UIDataDetectorTypes. Well, we won't really make use of UIDataDetectorTypes, but NSTextCheckingResult, since we'll be using an NSDataDetector. We already have TTTAttributedLabel available, but if you need something much more lightweight, like I did, follow along.

We'll see how we can interact with URLs, but the class should be easily extendable after. Why not use a UITextView, those can do this already?, you might ask; and you'd be right. But UITextViews are expensive to create, and if you need them insi […]


Continue reading →