Skip to content

Instantly share code, notes, and snippets.

View alfian0's full-sized avatar
🎯
Focusing

Muhammad Alfiansyah alfian0

🎯
Focusing
View GitHub Profile
extension UIViewController {
func add(_ child: UIViewController) {
addChildViewController(child)
view.addSubview(child.view)
child.view.frame = view.bounds
child.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
child.didMove(toParentViewController: self)
}
@alfian0
alfian0 / Cell.swift
Created May 1, 2018 10:02
Rounded tableView section
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let color = cell.backgroundColor?.cgColor
let cornerRadius: CGFloat = 5
cell.backgroundColor = .clear
let layer = CAShapeLayer()
let pathRef = CGMutablePath()
let bounds = cell.bounds.insetBy(dx: 20, dy: 0)
var addLine = false
extension NSMutableAttributedString {
func attr(_ link: String?, linkColor: UIColor, text: String) {
let pattern = "(\(text))"
let regex = try! NSRegularExpression.init(pattern: pattern,
options: NSRegularExpression.Options(rawValue: 0))
let matches = regex.matches(in: self.string,
options: NSRegularExpression.MatchingOptions(rawValue: 0),
range: NSRange.init(location: 0, length: self.string.count))
@alfian0
alfian0 / generateRandomPastelColor.swift
Created February 23, 2018 14:42 — forked from JohnCoates/generateRandomPastelColor.swift
Randomly generate pastel UIColor in Swift
// Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235
// Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro
// Method randomly generates a pastel color, and optionally mixes it with another color
func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor {
// Randomly generate number in closure
let randomColorGenerator = { ()-> CGFloat in
CGFloat(arc4random() % 256 ) / 256
}
var red: CGFloat = randomColorGenerator()
@alfian0
alfian0 / keyboardHeightObservable.swift
Created February 14, 2018 08:09 — forked from laurilehmijoki/keyboardHeightObservable.swift
RxSwift Observable on iOS keyboard height
import RxSwift // Version 3.2.0
import RxCocoa // Version 3.2.0
func keyboardHeight() -> Observable<CGFloat> {
return Observable
.from([
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow)
.map { notification -> CGFloat in
(notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
},
package official.alfian.useless;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams;
//
// KeychainService.swift
// PKBPartyKit
//
// Created by alfian0 on 2/6/18.
// Copyright Β© 2018 Extra Integer. All rights reserved.
//
import Foundation
import Security
//
// NetworkService.swift
// PKBPartyKit
//
// Created by alfian0 on 2/6/18.
// Copyright Β© 2018 Extra Integer. All rights reserved.
//
import ObjectMapper
import Moya
import UIKit
class MenuTransition: NSObject, UIViewControllerAnimatedTransitioning {
private var state: TransitionState = .present
private typealias Screens = (from: UIViewController, to: UIViewController)
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return PresentationController(presentedViewController: presented, presenting: presenting)
}
//
// Localized.swift
// PKBPartyKit
//
// Created by alfian0 on 1/19/18.
// Copyright Β© 2018 alfian0. All rights reserved.
//
// Taken from
// 1. https://github.com/marmelroy/Localize-Swift