Xcode color scheme

The official MABDEV Xcode color scheme !

What I tried to achieve:

  1. Better distinguish local and instance variables with color and italic ( I don’t like to use “self” when it’s unnecessary).
  2. Blue strings because red should be for errors.
  3. Bold types names ( more like Eclipse )

You’ll need the Consolas Font for a better result.

MABDEV Xcode Color scheme download

Hope you like it !

Cheers,

MAB

Good vibrations

Hi !  I was recently asked to make the iPhone vibrate while using the app (not by notification).  It’s been a while since I had to do it and back then it was in Obj-C. Here’s how to achieve it in Swift:

Cheers,

MAB

UIViewController extension for child view controller containment.

Hello !  I know its been a while, holidays and all …

Here’s a little extension that does no magic but shortens your code if you have to load child view controller from storyboards.  Sorry for the lack of syntax colouring, WordPress does not seem to support Swift yet.

[code language=”text”]
import Foundation

typealias ViewControllerStoryboardInfo = (name: String, id: String?)

protocol Container {
}

extension Container where Self: UIViewController {

func addChildViewController(withInfo info: ViewControllerStoryboardInfo)-> UIViewController? {

var viewController: UIViewController! = nil

switch info.id {
case let identifier where identifier != nil:
viewController = UIStoryboard(name: info.name, bundle: nil).instantiateViewController(withIdentifier: identifier!)
default:
viewController = UIStoryboard(name: info.name, bundle: nil).instantiateInitialViewController()
}

if let viewController = viewController {

self.addChildViewController(viewController)
viewController.view.frame = self.view.bounds
self.view.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)
return viewController
}

return nil
}

func removeAllChildViewController() {
self.childViewControllers.forEach({ (controller) in
controller.view.removeFromSuperview()
controller.willMove(toParentViewController: nil)
controller.removeFromParentViewController()
})
}
}
[/code]

 

Cheers,

MAB

Bring you app to life – A very simple guide to animated buttons and backgrounds

Hey !

I know its been a while, I am qui busy at Moment Factory right now.  Those guys are geniuses.  Anyway, I wanted to share with you, if you don’t already know it, how to animate anything that uses a UIImage aka. UIImageView, UIButton, etc…

To create an animated UIImage, include in you project a folder that contains your animation with a PNG for each frame.  The files needs to be named like this:

  • WhatEverNameYouWant-1
  • WhatEverNameYouWant-2
  • WhatEverNameYouWant-3
  • WhatEverNameYouWant-4

I strongly recommend not to include these in an asset file, if you try you’ll quickly understand why.

Then you create a UIImage :

You can the use it with a UIButton like you would with any other UIImage :

That’s it !  Have fun animating you apps !!

MAB

Make your custom view’s properties available in Storyboards

Let’s say you want to configure some parts of your view rendering directly in your storyboards.  Fortunately you can by using @IBInspectable.

Syntax

Result in Xcode

Screen Shot 2016-06-14 at 3.34.17 PM

Simulator

Screen Shot 2016-06-14 at 3.34.13 PM

Here is the project ( Xcode 8, Swift 3) if you want to try it : IBInspectableDemo

That’s it folks, have a good day !

MAB

 

How to outline your UILabel & UIButton

I recently had a problem with a yellow label on a dynamic background that can sometimes also be yellow.  The two common solutions are

  • Add a shadow.
  • Outline your text.

NSAttributedString offers everything you need to do it.

Filled & Outlined

Screen Shot 2016-06-09 at 1.32.07 PM

 

Filled ?

Note that the stroke width attribute is a negative value.

This is to tell the drawing engine it is a “Stroke & Fill” operation.  Otherwise it’ll just ignore the “NSForegroundColorAttributeName” and leave the text transparent like this :

Screen Shot 2016-06-09 at 1.44.33 PM

Link to the playground : MABDev.OutlinedText.playground

Documentation : https://developer.apple.com/library/mac/qa/qa1531/_index.html

Cheers,

MAB