swift 4

Swift 4: An extension to define UIColors with “normal” RGB values and set some named colors

UIColors require you to enter red, green and blue as values between 0 and 1. In pracitcal terms that means you need to divide your values by 255 to obtain the CGFloat required. Easy enough? Surely! Still it is a tad annoying, especially as the rest of the world will give you RGB values between […]

Swift 4: Pull To Refresh / UIRefreshControl

TableViews can have a useful feature to refresh the data inside of them, simply pull to refresh. Apple didn’t invent this, that was Loren Brichter of Tweetie, which was sold to Twitter and Twitter was eventually granted a Patent for the feature. Today this feature is absolutely ambiguous and very easy to implement. For example, […]

Swift 4: scale image to width

For an app that I was writing I needed an easy function to scale an image to a specific width, the function below will accomplish this: func scaleImageWidth(sourceImage:UIImage, scaledToWidth: CGFloat) -> UIImage { let oldWidth = sourceImage.size.width let scaleFactor = scaledToWidth / oldWidth let newHeight = sourceImage.size.height * scaleFactor let newWidth = oldWidth * scaleFactor […]

Scroll to top