Skip to content

Instantly share code, notes, and snippets.

View iOSDigital's full-sized avatar

Paul iOSDigital

View GitHub Profile
@iOSDigital
iOSDigital / insertHTMLTags.m
Last active January 2, 2016 22:19
iOS: a method to add basic html tags into a UITextView. In this example there are 4 buttons, bold, italic, underline, link. In my app these buttons are in an inputAccessoryView, and they are tagged 1,2,3,4. If no text is selected, the method just inserts the tags at the cursor position, and then sets the cursor position in between the opening an…
-(IBAction)insertHTMLTags:(id)sender {
NSRange selectRange = [textComment selectedRange];
NSUInteger selectLength = selectRange.length;
NSString *openingTag,*closingTag;
switch ([sender tag]) {
case 1:
openingTag = @"<strong>";
closingTag = @"</strong>";
@iOSDigital
iOSDigital / gist:8379249
Created January 12, 2014 01:14
UIImage doesn't have a tint colour. UIImageView does. This little method returns a UIImage, tinted with a UIColor. It's useful for things like table icons, where the image view is read only. Means you don't have to create loads of PNGs in different colours.
-(UIImage *)imageWithTint:(UIImage *)image andTintColor:(UIColor *)tintColor {
UIImage *imageNew = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithImage:imageNew];
imageView.tintColor = tintColor;
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0.0);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@iOSDigital
iOSDigital / invertedImageWithColor.m
Created April 1, 2017 17:44
invertedImageWithColor
-(UIImage *)invertedImageWithColor:(UIColor*)color {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect contextRect = CGContextGetClipBoundingBox(context);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, contextRect);
[self drawInRect:contextRect blendMode:kCGBlendModeDestinationOut alpha:1.0];
@iOSDigital
iOSDigital / UIViewExtensions.swift
Created February 25, 2019 13:04
Swift UIView extension to add rounded corners and a drop shadow to a view, avoiding the clipsToBounds problem
import Foundation
import UIKit
public extension UIView {
func roundCornerWithShadow(cornerRadius: CGFloat, shadowRadius: CGFloat, offsetX: CGFloat, offsetY: CGFloat, colour: UIColor, opacity: Float) {
self.clipsToBounds = false