Skip to content

Instantly share code, notes, and snippets.

View sseno's full-sized avatar
🐈
Working from anywhere

sseno

🐈
Working from anywhere
  • Privy
  • Yogyakarta, Indonesia
View GitHub Profile
@evil159
evil159 / SizeableCollectionViewCell.swift
Created March 6, 2019 08:29
A base cell that works with MagazineLayout for nib based cells.
open class SizeableCollectionViewCell: UICollectionViewCell {
private var widthConstraint: NSLayoutConstraint!
public override init(frame: CGRect) {
super.init(frame: frame)
contentView.translatesAutoresizingMaskIntoConstraints = false
let bottomConstraint = bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
bottomConstraint.priority = .required - 1
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@saito-sv
saito-sv / Shimmer.swift
Last active June 24, 2024 18:22
a simple shimmer view in swift
// Created by Marlon Monroy on 5/19/18.
// Copyright © 2018 Monroy.io All rights reserved.
//
import Foundation
import UIKit
protocol Shimmerable {
func start(count: Int) -> Void
@shaildyp
shaildyp / UIView+roundCorners.swift
Last active December 7, 2022 12:14
Backward compatible maskedCorners of iOS 11.
extension UIView {
func roundCorners(_ corners: CACornerMask, radius: CGFloat) {
if #available(iOS 11, *) {
self.layer.cornerRadius = radius
self.layer.maskedCorners = corners
} else {
var cornerMask = UIRectCorner()
if(corners.contains(.layerMinXMinYCorner)){
cornerMask.insert(.topLeft)
@Jeevuz
Jeevuz / Extensions.kt
Last active January 3, 2023 10:25
Here I collect some of my most useful Kotlin extensions
inline fun SharedPreferences.edit(changes: SharedPreferences.Editor.() -> SharedPreferences.Editor) {
edit().changes().apply()
}
fun ImageView.tintSrc(@ColorRes colorRes: Int) {
val drawable = DrawableCompat.wrap(drawable)
DrawableCompat.setTint(drawable, ContextCompat.getColor(context, colorRes))
setImageDrawable(drawable)
if (drawable is TintAwareDrawable) invalidate() // Because in this case setImageDrawable will not call invalidate()
}
@samwarnick
samwarnick / UIRoundedButtonWithGradientAndShadow.swift
Last active December 26, 2021 16:45
A rounded button with a gradient and shadow written in swift
class UIRoundedButtonWithGradientAndShadow: UIButton {
let gradientColors : [UIColor]
let startPoint : CGPoint
let endPoint : CGPoint
required init(gradientColors: [UIColor],
startPoint: CGPoint = CGPoint(x: 0, y: 0.5),
endPoint: CGPoint = CGPoint(x: 1, y: 0.5)) {
self.gradientColors = gradientColors
@ylem
ylem / CenterItemInCollectionView.playground
Last active January 5, 2024 03:28
Scrolling item on a horizontal UICollectionView, stopped item on center of screen.
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class WLCollectionCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@gnou
gnou / TextSize.swift
Created March 21, 2017 10:09
Calculate height of some text when width is fixed
public struct TextSize {
fileprivate struct CacheEntry: Hashable {
let text: String
let font: UIFont
let width: CGFloat
let insets: UIEdgeInsets
fileprivate var hashValue: Int {
return text.hashValue ^ Int(width) ^ Int(insets.top) ^ Int(insets.left) ^ Int(insets.bottom) ^ Int(insets.right)
@lopspower
lopspower / README.md
Last active July 5, 2024 10:20
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store