Skip to content

Instantly share code, notes, and snippets.

View gali8's full-sized avatar

Daniele - mokapp.com gali8

View GitHub Profile
@gali8
gali8 / NexorPageControl.swift
Created May 15, 2020 00:22
UIPageControl with custom dots and space
import UIKit
class NexorPageControl: UIPageControl {
fileprivate let activeDotFrame = CGRect(origin: .zero, size: CGSize(width: 21, height: 7))
fileprivate let inactiveDotFrame = CGRect(origin: .zero, size: CGSize(width: 7, height: 7))
fileprivate let dotPadding: CGFloat = 9 //default is 9
lazy var activeImage: UIImage = {
let view = UIView(frame: self.activeDotFrame)
@gali8
gali8 / PushManager+Handler-prepareNotification.swift
Created February 20, 2020 11:24
DynamicPushAnswers - handler
func prepareNotification(content: UNNotificationContent, userInfo: [AnyHashable: Any], completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){
// Register the notification type.
let notificationCenter = UNUserNotificationCenter.current()
var json = JSON(userInfo)
guard let data = json["data"].dictionary else {
completionHandler([ .alert, .sound, .badge ])
return
}
@gali8
gali8 / dynamicpush.json
Created February 20, 2020 11:23
DynamicPushAnswers Json
{
"aps": {
"alert": {
"title": "www.nexor.it",
"body": "Rispondi a questo interessante sondaggio"
},
"sound": "default",
"mutable-content": 1
},
"data": {
let color = UIColor(named: "background") //always works
let image = UIImage(named: "background")
@gali8
gali8 / Need_an_imageRef.swift
Last active September 23, 2019 12:46
'NSInternalInconsistencyException', reason: 'Need an imageRef'- iOS13
//Need an imageRef error
let image = UIImage(named: "background") //works only if an image named "background" exists else crash!
let color = UIColor(named: "background") //always works
class LabelBody: LabelTappable {
var body: String? {
get {
return self.attributedText?.string
}
set {
self.text = nil
guard let text = newValue, !text.isEmpty else {
self.attributedText = nil
import UIKit
class LabelTappable: UILabel {
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer(size: CGSize.zero)
let tapGesture = UITapGestureRecognizer()
var textStorage = NSTextStorage() {
didSet {
import UIKit
extension String {
func html(font: UIFont) -> NSAttributedString? {
do {
let modifiedText = String(format: "<span style=\"font-family: \(font.fontName); font-size: \(font.pointSize)\">%@</span>", self) as String
let attrStr = try NSAttributedString(
data: modifiedText.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],
https://samples.openweathermap.org/data/2.5/forecast/daily?q=München,DE&appid=b6907d289e10d714a6e88b30761fae22
https://openweathermap.org/forecast16#name16
http://openweathermap.org/img/w/