Skip to content

Instantly share code, notes, and snippets.

@DocMacFain
DocMacFain / title.swift
Created April 3, 2016 11:10
Title with subtitle
let titleLabel = UILabel(frame: CGRectMake(0, 0, 0, 0))
titleLabel.backgroundColor = UIColor.clearColor()
titleLabel.textColor = UIColor.blackColor()
titleLabel.font = titleLabel.font.fontWithSize(18)
titleLabel.text = "Title"
titleLabel.sizeToFit()
let subTitleLabel = UILabel(frame: CGRectMake(0, 20, 0, 0))
subTitleLabel.backgroundColor = UIColor.clearColor()
subTitleLabel.textColor = UIColor.blackColor()
@DocMacFain
DocMacFain / swift.swift
Created April 10, 2016 07:42
Removing highlighted delay from bin on UITableView
for currentView in tableView.subviews {
if currentView.isKindOfClass(UIScrollView) {
(currentView as? UIScrollView)?.delaysContentTouches = false
break
}
}
@DocMacFain
DocMacFain / fb.swift
Created May 25, 2016 12:45
fb question
import Foundation
func printNum(i: Int) {
print(i, separator: "", terminator: ", ")
}
func printFizz(i: Int) {
print("Fizz", separator: "", terminator: ", ")
}
@DocMacFain
DocMacFain / CustomAlertController.swift
Created June 18, 2016 04:53
Custom alert controller
let alert = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.Alert)
let alertView: UIView = NSBundle.mainBundle().loadNibNamed("View", owner: self, options: nil)[0] as! UIView
alertView.frame = CGRectMake(alert.view.bounds.minX, alert.view.bounds.minY, 200, 200)
alert.view.addSubview(alertView)
let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
@DocMacFain
DocMacFain / reload.swift
Last active July 6, 2016 07:01
reload.swift
// presenter
func beginLoadingData() {
NetworkManager.sharedInstance.loadMoreQuestions { (result) in
switch result {
case .Ok:
self.view.updateData(questions)
self.view.insert()
case .BackendError:
self.view.showAlertController(...)
@DocMacFain
DocMacFain / willDisplayLogic.swift
Last active July 6, 2016 06:39
willDisplayLogic.swift
// view
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == tableView.indexPathsForVisibleRows?.last?.row {
let lastSection = tableView.numberOfSections - 1
let lastRow = tableView.numberOfRowsInSection(lastSection) - 1
if indexPath.section == lastSection && indexPath.row == lastRow {
if self.questions.count < Int(self.countersCellDataPack.questionsAmount!) {
@DocMacFain
DocMacFain / cellForRowAtIndexPath.swift
Created July 5, 2016 20:30
cellForRowAtIndexPath.swift
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch (section: indexPath.section, row: indexPath.row) {
case (0, 0):
let cell = tableView.dequeueReusableCellWithIdentifier(headerCellIdentifier, forIndexPath: indexPath) as! HeaderCellView
fillHeaderCellWithData(cell)
return cell
case (0, 1):
let cell = tableView.dequeueReusableCellWithIdentifier(userNameCellIdentifier, forIndexPath: indexPath) as! UserNameCellView
fillUserNameCellWithData(cell)
return cell
@DocMacFain
DocMacFain / data.txt
Created November 6, 2016 22:07
Ada task
6 0.13
23000
23000
20439
90000
12033
20420
@DocMacFain
DocMacFain / fib.js
Last active January 13, 2017 16:55
fib
function functionVersionFib(n) {
if (n == 0 || n == 1) {
return n;
} else {
return functionVersionFib(n - 1) + functionVersionFib(n - 2);
}
}
@DocMacFain
DocMacFain / Color.swift
Created February 14, 2017 17:45
How to manage colors in project
//
// Color.swift
// Color
//
// Created by Sergei Fabian on 14.02.17.
// Copyright © 2017 com.sfabian. All rights reserved.
//
import UIKit