Skip to content

Instantly share code, notes, and snippets.

View vukcevich's full-sized avatar

Marijan Vukcevich vukcevich

  • Huntington Beach, California
View GitHub Profile
//
// anyCodabelValue.swift
// Sajjad Sarkoobi
//
// Created by Sajjad Sarkoobi on 6/8/20.
// Copyright © 2020 Sajjad Sarkoobi. All rights reserved.
// Email: [email protected]
import Foundation
func resizedImage(for size: CGSize) -> UIImage? {
let image = self.cgImage
let context = CGContext(data: nil,
width: Int(size.width),
height: Int(size.height),
bitsPerComponent: image!.bitsPerComponent,
bytesPerRow: Int(size.width),
space: image?.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!,
bitmapInfo: image!.bitmapInfo.rawValue)
context?.interpolationQuality = .high
@vukcevich
vukcevich / NativeWebView.swift
Created February 6, 2021 20:03 — forked from maxcampolo/NativeWebView.swift
WKWebView setup to make a web page adopt native behavior.
import WebKit
class NativeWebViewController: UIViewController {
let viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);"
let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';"
let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';"
override func viewDidLoad() {
// 1 - Make user scripts for injection
@vukcevich
vukcevich / MultipleTapLabel.swift
Created July 23, 2020 15:05 — forked from hamdan/MultipleTapLabel.swift
Create Multiple Tappable Links in a UILabel
extension UITapGestureRecognizer {
func didTapAttributedTextInLabel(label: UILabel, targetText: String) -> Bool {
guard let attributedString = label.attributedText, let lblText = label.text else { return false }
let targetRange = (lblText as NSString).range(of: targetText)
//IMPORTANT label correct font for NSTextStorage needed
let mutableAttribString = NSMutableAttributedString(attributedString: attributedString)
mutableAttribString.addAttributes(
[NSAttributedString.Key.font: label.font ?? UIFont.smallSystemFontSize],
range: NSRange(location: 0, length: attributedString.length)
@vukcevich
vukcevich / UIImage+Rotation.swift
Created December 15, 2019 16:30 — forked from norsez/UIImage+Rotation.swift
Rotate UIImage by radians in Swift 3
extension UIImage {
func image(withRotation radians: CGFloat) -> UIImage {
let cgImage = self.cgImage!
let LARGEST_SIZE = CGFloat(max(self.size.width, self.size.height))
let context = CGContext.init(data: nil, width:Int(LARGEST_SIZE), height:Int(LARGEST_SIZE), bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: cgImage.colorSpace!, bitmapInfo: cgImage.bitmapInfo.rawValue)!
var drawRect = CGRect.zero
drawRect.size = self.size
let drawOrigin = CGPoint(x: (LARGEST_SIZE - self.size.width) * 0.5,y: (LARGEST_SIZE - self.size.height) * 0.5)
/*
* Example implementation
*/
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
println("Launched with URL: \(url.absoluteString)")
let userDict = self.urlPathToDictionary(url.absoluteString)
//Do something with the information in userDict
# Building FAT librares for XCode 10
set -e
# If we're already inside this script then die
if [ -n "$MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export MULTIPLATFORM_BUILD_IN_PROGRESS=1
@vukcevich
vukcevich / DataProviding.swift
Created July 30, 2019 18:16 — forked from Frankacy/DataProviding.swift
Swift data provider/presenter
//
// DataProviding.swift
// GenericsDataSource
//
// Created by Frank Courville on 2019-05-09.
// Copyright © 2019 iOS Coach Frank. All rights reserved.
//
import UIKit
import CoreData
import UIKit
struct Photo {}
class PhotoDetailViewController: UIViewController {
var photo: Photo!
var context: NSManagedObjectContext!
}
@vukcevich
vukcevich / DependencyInjectionExample.swift
Created March 26, 2019 17:10 — forked from eofster/DependencyInjectionExample.swift
Dependency injection example with tests
import Foundation
import XCTest
//////////////////////////////////////////////////////////////////////
// Preferences
protocol UserDefaults {
func stringForKey(key: String) -> String
}