Skip to content

Instantly share code, notes, and snippets.

View aybekckaya's full-sized avatar
🏠
Working from home

Aybek Can Kaya aybekckaya

🏠
Working from home
View GitHub Profile
//
// StringExtensions.swift
// PlistSwift
//
// Created by aybek can kaya on 16/01/16.
// Copyright © 2016 aybek can kaya. All rights reserved.
//
import Foundation
@aybekckaya
aybekckaya / loadableShimmer.swift
Created June 25, 2018 23:52
Loading view like Facebook
extension UIView {
func animateLoading () {
let gradient = CAGradientLayer()
gradient.startPoint = CGPoint(x: 0, y: 0)
gradient.endPoint = CGPoint(x: 1, y: 0)
gradient.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width*3, height: self.bounds.size.height)
let lowerAlpha: CGFloat = 0.75
let solid = UIColor(white: 1, alpha: 1).cgColor
@aybekckaya
aybekckaya / collectionViewCustom.swift
Last active June 27, 2018 01:51
Collection view with blocks
//
// CollectionView.swift
// Trendyol
//
// Created by aybek can kaya on 12/06/2018.
// Copyright © 2018 aybek can kaya. All rights reserved.
//
import UIKit
@aybekckaya
aybekckaya / NibLoadingProtocol.swift
Created June 25, 2018 23:56
easy view loading with {UIView}.identifier
protocol ComponentIdentifier: class {
static var identifier: String { get }
}
extension ComponentIdentifier {
static var identifier: String { return String(describing: self) }
}
extension UIView {
@aybekckaya
aybekckaya / SampleNetworkingEnum.swift
Created June 25, 2018 23:58
Sample Networking with RxSwift and Alamofire
typealias NetworkResponse = (data:JSON? , error:NetworkError?)
enum NetworkError {
case userNotFound
case cannotGetUserId
case cannotGetServerResponse
case unknownError
func stringify()->String {
switch self {
@aybekckaya
aybekckaya / UIColor+extensions.swift
Created June 26, 2018 00:00
UIColor extensions
public extension UIColor {
public convenience init(hex: Int, alpha: CGFloat = 1.0) {
let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0
let green = CGFloat((hex & 0xFF00) >> 8) / 255.0
let blue = CGFloat((hex & 0xFF)) / 255.0
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
enum AppFont {
case regularFont
case boldFont
case italicBoldFont
case italicFont
func font(size:CGFloat)->UIFont {
switch self {
case .boldFont: return UIFont(name: "Arial-BoldMT", size: size)!
case .italicBoldFont: return UIFont(name: "Arial-BoldItalicMT", size: size)!
extension String {
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil)
return ceil(boundingBox.height)
}
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
extension Int {
static func randomNumber(min:Int , max:Int)->Int {
var minimum = min
var maximum = max
if minimum < 0 { minimum = 0 }
if maximum < 0 { maximum = 0 }
if minimum == maximum { return minimum }
else if minimum > maximum { return randomNumber(min:maximum , max:minimum) }
return minimum + Int(arc4random())%(maximum - minimum)
}
enum NavigationBarType {
case closeOnRight
}
class BaseViewController: UIViewController {
fileprivate static let barButtonSize = CGSize(width: 30, height: 30)
fileprivate enum NavigationBarButtonType {
case closeBtn