Skip to main content

Tech

UIScrollViews and auto layout

4 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)
  self.view.addSubview(sv)
  
  sv.translatesAutoresizingMaskIntoConstraints = false
  sv.alignTop("0", leading: "0", bottom: "0", trailing: "0", toView: self.view)
  
  return sv
}()

We have a scrollView that is the same size of our view, nothing fancy.

Continue reading →

Content blockers and assets

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

1 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 to call them for 3 days in a row, and to drive to one of their offices to get the needed info.

Continue reading →

Changing (just) the font size of a button

45 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

1 min 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.

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.

Content hugging and compression resistance

45 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 out, I actually wish I could have had something like this guide to help me out.

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:

Continue reading →