Skip to content

Instantly share code, notes, and snippets.

View pruinis's full-sized avatar

Anton M. pruinis

  • Ukraine
View GitHub Profile
@IanKeen
IanKeen / LayoutGuideProvider.swift
Created October 31, 2017 11:57
Extension for constraints pointing to either the view or safeAreaLayoutGuide depending on availability
protocol LayoutGuideProvider {
var leadingAnchor: NSLayoutXAxisAnchor { get }
var trailingAnchor: NSLayoutXAxisAnchor { get }
var leftAnchor: NSLayoutXAxisAnchor { get }
var rightAnchor: NSLayoutXAxisAnchor { get }
var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var widthAnchor: NSLayoutDimension { get }
var heightAnchor: NSLayoutDimension { get }
var centerXAnchor: NSLayoutXAxisAnchor { get }
@uy
uy / gist:3d9f4bd9c28063416f9da42425bb9430
Last active September 28, 2021 15:33
Custom Checkbox iOS Swift
import UIKit
class CheckBox: UIButton {
// Images
let checkedImage = UIImage(named: "ic_check_box")! as UIImage
let uncheckedImage = UIImage(named: "ic_check_box_outline_blank")! as UIImage
// Bool property
var isChecked: Bool = false {
didSet{
@freak4pc
freak4pc / MKMultiPoint+Ext.swift
Last active September 5, 2024 06:36
Get a list of coordinates from a MKPolyline / MKRoute
public extension MKMultiPoint {
var coordinates: [CLLocationCoordinate2D] {
var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid,
count: pointCount)
getCoordinates(&coords, range: NSRange(location: 0, length: pointCount))
return coords
}
}
anonymous
anonymous / UIColor+Helper.swift
Created September 13, 2015 14:04
UIColor from Hex String in Swift
import UIKit
extension UIColor {
convenience init(hex: String, alpha: CGFloat = 1) {
assert(hex[hex.startIndex] == "#", "Expected hex string of format #RRGGBB")
let scanner = NSScanner(string: hex)
scanner.scanLocation = 1 // skip #
var rgb: UInt32 = 0
@onmyway133
onmyway133 / DNLastItemCenteredLayout
Created June 15, 2015 08:48
DNLastItemCenteredLayout.m
#import "DNLastItemCenteredLayout.h"
@implementation DNLastItemCenteredLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attribute in attributes) {
NSInteger itemCount = [self.collectionView.dataSource collectionView:self.collectionView
numberOfItemsInSection:attribute.indexPath.section];
@scottdelly
scottdelly / FacebookLogin.swift
Last active April 23, 2021 21:43
Facebook Login with iOS SDK 4.0 in Swift
//If you have a Bridging-Header:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
//In your AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [String: AnyObject]?) -> Bool {
//App launch code
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
//Optionally add to ensure your credentials are valid:
@bwhiteley
bwhiteley / gist:049e4bede49e71a6d2e2
Last active March 17, 2024 13:10
Initialize Swift subclass of UIView, designed in .xib
// Create CustomView.xib, set File's Owner to CustomView.
// Link the top level view in the XIB to the contentView outlet.
class CustomView : UIView {
@IBOutlet private var contentView:UIView?
// other outlets
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
@gilserrap
gilserrap / gist:5988b982c3ae7f2ae081
Created July 9, 2014 10:28
Getting coordinates for a MKPolyline
- (void)testThis:(MKPolyline *)stepPolyline
{
//route is the MKRoute in this example
//but the polyline can be any MKPolyline
NSUInteger pointCount = stepPolyline.pointCount;
//allocate a C array to hold this many points/coordinates...
CLLocationCoordinate2D *routeCoordinates
@NeuralGlue
NeuralGlue / gist:6907596
Last active March 3, 2016 12:42
Category to hide the status bar for a UIImagePickerController in IOS 7+
//
// UIImagePickerController+RemoveStatusBar.m
// CarpeWorkshop
// With thanks to:http://stackoverflow.com/users/2797041/user2797041
// Created by Charles Young on 10/9/13.
// Copyright (c) 2013 Charles Young. All rights reserved.
//
#import "UIImagePickerController+RemoveStatusBar.h"
@Lejdborg
Lejdborg / uitextview-margin.m
Created September 14, 2013 19:27
How to add left and right margins to a UITextView...
float padding = 10.0;
NSMutableParagraphStyle *editorParagraphStyle = [NSMutableParagraphStyle new];
[editorParagraphStyle setHeadIndent:padding];
[editorParagraphStyle setFirstLineHeadIndent:padding];
[editorParagraphStyle setTailIndent:-padding];
NSDictionary *textAttributes = @{
NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:14],
NSParagraphStyleAttributeName: editorParagraphStyle