Quantcast
Channel: Rob Bamforth's Blog
Browsing latest articles
Browse All 35 View Live

Swift iOS – Add pinch gesture to UIImageView (imageview)

Create gesture and add it to your imageview in ViewDidLoad(): let standardPinch = UIPinchGestureRecognizer(target: self, action: #selector(pinch)) standardPinch.delegate = self...

View Article



Swift iOS – Check model, check if iPad, check if iPhone, Other

How to check device type and run specific code for iPad or iPhone. witch UIDevice.current.userInterfaceIdiom { case .phone: print("phone") case .pad: print("ipad") case .unspecified:...

View Article

Swift iOS – How to turn a positive number into a negative number, negative...

Here is a super simple method to reverse a posative or negative number in swift: func reversePosNeg(number: Int) -> Int{ return -number } Usage: let reversedNumber = reversePosNeg(number: -99)...

View Article

Swift iOS – How to detect Orientation change (landscape, portrait)

Add Notification Center observer in ViewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(orientationChange), name: UIDevice.orientationDidChangeNotification, object: nil) Add...

View Article

Image may be NSFW.
Clik here to view.

Xcode – How to install Pods (Cocoa Pods)

Xcode + developer tools must be installed on your Mac. 1. Open Terminal and run the following command to install Cocoa Pods for Xcode: sudo gem install cocoapods Enter your Mac password. The required...

View Article


Swift iOS – How to add an outline border to UISwitch

mySwitch.layer.borderColor = UIColor.lightGray.cgColor mySwitch.layer.borderWidth = 2 mySwitch.layer.cornerRadius = 15

View Article

Swift iOS – Round double to X decimal places

Simple method to trim double: func roundDouble(value: Double, decimalPlaces: Int) -> Double{ let response = Double(String(format: "%.\(decimalPlaces)f", value)) return response ?? 0.0 } Usage: let...

View Article

Swift iOS – How to keep line breaks when translating text with ML Kit on iOS

ML Kit translate is a powerful language translation tool, but when translating a passage of text containing line breaks, the returned translated text has the line breaks stripped out. I’ve tried a...

View Article


Swift iOS – How to programmatically tap UIButton

Quick and easy way to simulate UIButton tap, in code: myButton.sendActionsForControlEvents(.TouchUpInside)

View Article


Swift iOS – Remove all subviews from view

Remove all subsview from a UIView: view.subviews.forEach({ $0.removeFromSuperview() })

View Article
Browsing latest articles
Browse All 35 View Live




Latest Images