Skip to content

Instantly share code, notes, and snippets.

View hemangshah's full-sized avatar
🎯
Focusing

Hemang hemangshah

🎯
Focusing
  • Stockholm, Stockholm County, Sweden
View GitHub Profile
import UIKit
enum LayoutableButtonVerticalAlignment: String {
case center
case top
case bottom
case unset
}
enum LayoutableButtonHorizontalAlignment: String {
@perlguy99
perlguy99 / Alamofire.request.error.handling.swift
Last active January 16, 2023 19:52
Alamofire Request Error Handling - From their documentation
Alamofire.request(urlString).responseJSON { response in
guard case let .failure(error) = response.result else { return }
if let error = error as? AFError {
switch error {
case .invalidURL(let url):
print("Invalid URL: \(url) - \(error.localizedDescription)")
case .parameterEncodingFailed(let reason):
print("Parameter encoding failed: \(error.localizedDescription)")
print("Failure Reason: \(reason)")
@sauvikatinnofied
sauvikatinnofied / MediumBlogFontHandling_FullCode.swift
Last active October 25, 2023 14:57
MediumBlogFontHandling_FullCode
import Foundation
import UIKit
// Usage Examples
let system12 = Font(.system, size: .standard(.h5)).instance
let robotoThin20 = Font(.installed(.RobotoThin), size: .standard(.h1)).instance
let robotoBlack14 = Font(.installed(.RobotoBlack), size: .standard(.h4)).instance
let helveticaLight13 = Font(.custom("Helvetica-Light"), size: .custom(13.0)).instance
struct Font {
import UIKit
extension UIImage {
// colorize image with given tint color
// this is similar to Photoshop's "Color" layer blend mode
// this is perfect for non-greyscale source images, and images that have both highlights and shadows that should be preserved
// white will stay white and black will stay black as the lightness of the image is preserved
func tint(tintColor: UIColor) -> UIImage {
@smswz
smswz / GridLayout.swift
Last active July 3, 2023 15:51
A simple custom grid UICollectionViewLayout
// MIT License
//
// Copyright (c) 2016 stable|kernel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@reloni
reloni / gist:62a09f0e67631f62e38b5a3566e0f6bf
Last active April 17, 2018 03:55
Add blur to UITableView (Swift 3)
tableView.backgroundColor = UIColor.clear()
let blurEffect = UIBlurEffect(style: .light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
tableView.backgroundView = blurEffectView
@benbahrenburg
benbahrenburg / BaseController.swift
Last active October 4, 2018 16:57
Adding Consistent Back Button to view
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let backTitle = NSLocalizedString("Back", comment: "Back button label")
self.addBackbutton(backTitle)
@daniellevass
daniellevass / sharing_data_ios.md
Last active September 21, 2022 23:06
Sharing Data between iPhone and Apple Watch apps

#Sharing Data between iPhone and Apple Watch apps

So we've already taken a look at some of the issues we've faced building our Whiskr Apple Watch app, next we're going to look into how we shared data between the iPhone and Apple Watch app. This was probably one of the hardest aspects to learn and get right, and the current documentation isn't all that great!

To do this we'll have to create an App Group which is essentially a space which both apps can use. It was brought in with the exetension framework in iOS8 so apps can communicate with their Today widgets, or custom keyboards, and amongst other applications.

Add Capabilities

The first thing we have to do is add the app group capability to both our iPhone and Watch Watch Extension targets.

@calt
calt / Tabbar.Swift
Last active January 9, 2024 05:58
UITabBar with custom height in Swift, does not work for iOS 14 or later.
// Does not work on iOS 14.0 or later, keeping the gist just for reference.
extension UITabBar {
override open func sizeThatFits(size: CGSize) -> CGSize {
super.sizeThatFits(size)
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 71
return sizeThatFits
}
}