Adding and customizing UIButtons in storyboard is extremely easy (and I would recommend doing it that way whenever possible), but what if you need to do it yourself in code? The process takes only couple of lines of code, but it can escalate quickly if you add multiple buttons. To keep code clean I’ve created …
Author Archives: mmv
Animating UIView by changing constraints
That’s one of the most fun and easiest animations you can do. First, let’s make sure we know what constraint to change: you’ll have to make sure you either have the constraint as an @IBOutlet or -if you’ve added in code- make sure you add an identifier to it. Then you’ll trigger a constant change …
Opening links in Safari / Embedded Safari – iOS
In iOS you can either do it with a push: let safariVC = SFSafariViewController(url: URL(string: “www.google.com”)!, configuration: .init()) present(safariVC, animated: true, completion: nil) or directly in the Safari app: UIApplication.shared.open(URL(string:“www.google.com”)!, options: [:]) { (_) in } Very practical, Marc
Reloading/inserting Dynamic Height cells and keeping Scroll position
For an upcoming app I had to insert Dynamic Height cells while keeping the tableView offset -scrolling position- constant. This would typically be a trivial issue, but given that when using Dynamic Height cells nor the contentSize nor the offset can be trusted it’s a bit more tricky than it seems… What I was trying …
Continue reading “Reloading/inserting Dynamic Height cells and keeping Scroll position”
Measuring function execution time
This is a very quick one. For an app I’m working on I wanted to measure how long it took a given function to complete. I typically don’t do this, as most functions are very fast, but this one involved a server fetch and some background processing. Anyhow, I’m getting distracted, here it is -easy …
Dealing with UIGraphics ImageContext ‘Memory Leaks’
Here’s the code to change the image size of an image in iOS so that then it can be saved with smaller footprint: let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height) // Actually do the resizing to the rect using the ImageContext stuff UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) image.draw(in: rect) …
Continue reading “Dealing with UIGraphics ImageContext ‘Memory Leaks’”
Pre-Scrolling a Table to a specific cell at load
Although that’s something that appears fairly easy, the truth -for me at least-, is that scrolling a UITableView to a specific cell every time you load it may prove tricky. In the app I’m working on I implement it in the following way: every time a view appeared I assess if the top visible row …
Continue reading “Pre-Scrolling a Table to a specific cell at load”
Find the right value in an Array, or in an Array of Dictionaries
From time to time I discover a new way of coding something that significantly improves readability & minimizes how much I need to code. Here’s one of such latest discoveries. Typically to find a value in an array (or in an array of dictionaries) with a specific condition I would do a for loop with …
Continue reading “Find the right value in an Array, or in an Array of Dictionaries”
Inserting cells at the top of a UITableView with no scrolling
If you would like your table to be refreshed “ala Twitter”, with new data being added on top, here’s a quick an easy way to do it for iOS: func updateTableViewAfterAdditionInNewArray(){ //Get new feeds and check if counts are different let countOfAddedItems = oldArray.count – newArray.count …
Continue reading “Inserting cells at the top of a UITableView with no scrolling”
Improve your ⌘ V efficiency
Want to improve your quality of life in 5 seconds? 1. Go to System Preferences 2. Keyboard 3. Shortcuts -> App Shortcuts 4. Click on add -> All Applications –> add “Paste and Match Style” for keyboard shortcut ⌘V Thank you Ally Marc