UIScrollViews and auto layout

:  ~ 2 min read

UIScrollViews are a different kind of beast when created with auto layout, but the basic idea is to constrain it to a fixed frame, and let the constraints of its subviews determine its contentSize. So let's start with that:

private lazy var scrollView: UIScrollView = {
  let sv = UIScrollView(frame: CGRect.zero)
  sv.translatesAutoresizingMaskIntoConstraints = false
  sv.alignTop(nil, leading: nil, bottom: nil, trailing: nil, toView: self.view)

  return sv

We […]

Continue reading →

Content blockers and assets

:  ~ 25 sec read

If you're using any kind of offsite assets, like webfonts or Font Awesome icons, take into consideration that these will be blocked by iOS 9's content blockers - either bring them locally on your server, either have fallbacks; I chose the former, which also improved the pages' loading times.

DHL Express

:  ~ 2 min read

I recently bought a couple of cases for the Apple Watch and I had the option to ship via USPS or DHL, and since DHL was only $10 more expensive, I thought sure, it's worth it.

Sorry for the rant post, but I'm really, really disappointed. Long story short, if there are other options, I doubt I will choose DHL again - I had a terrible customer service experience.

The problems started with the fact that I wasn't announced when the package arrived at the customs and couldn't be moved further because they need extra info - I had […]

Continue reading →

Changing (just) the font size of a button

:  ~ 25 sec read

We have in the app a generic button, styled to look the same across the app - from shadows to title. Some places require a smaller font though, and I didn't really want to duplicate code, so something had to be done. Here's my little trick for it:

// titleLabel is nil only for system buttons, as per documentation
button.titleLabel!.font = UIFont(
  name: button.titleLabel!.font.fontName,
  size: button.titleLabel!.font.pointSize - 2

Auto Layout and transitionWithView

:  ~ 52 seconds read

If you want to animate the hidden property of a view, or animate the title of a button, the solution is simple - use UIView.transitionWithView(button [...]. If you want to animate the title of several buttons, the solution is just as simple - use UIView.transitionWithView(containerView [...].

The problem arises when you want to animate constraint changes at the same time: they won't be animated anymore, no matter if you encapsulate them in the same transitionWithView call, a new one, or inside an animateWithDuration call.

The only solution I found is to do a transitionWithView call for each button […]

Continue reading →

Diving into Auto Layout

This is one of the best articles I read about Auto Layout, and one of the best articles about a given topic, altogether. I really, really enjoyed reading it.

Pattern matching in Swift

One of the best explanations about pattern matching in swift I've seen so far. Insta-bookmark.

Content hugging and compression resistance

:  ~ 40 sec read

Even though the names might sound self-explanatory, I never really understood how they work. But I finally found a proper explanation about them:

A strong hugging priority limits the view from growing much larger than the content it presents. A weak priority may allow a view to stretch and isolate its content among a sea of padding. Compression resistance describes how a view attempts to maintain its minimum intrinsic content size.

I'm considering to buy the book too, while I'm at it.

Update, 2015-09-16: This piece is really, really nice as well. As he points out:

When I first started […]

Continue reading →

Subscriber Share for streaming music

:  ~ 1 min read

I recently saw this medium post linked on The Loop, and at first I thought "sure, this is a major issue, but, on the other hand, it seems pretty fair to be paid by the number of plays, that's what streaming means; I can't see any another way", but eventually I reached the part where he offers a solution; and I think it's perfect:

The premise behind Subscriber Share is simple: the only artists that should receive your money are the artists you listen to. Subscriber Share simply divides up your $7 ($10 per month, -30% service fees) based […]

Continue reading →

Breaking Cocoa

This was a fun Saturday morning read. And very interesting.