Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / gist:2751fb3ce32792b8a85d
Last active February 21, 2023 12:06
Swift: create CGPath from attributed string
func appendToPath(path: CGMutablePath)
{
let textPath = CGPathCreateMutable()
let attributedString = NSAttributedString(string: string)
let line = CTLineCreateWithAttributedString(attributedString)
// direct cast to typed array fails for some reason
let runs = (CTLineGetGlyphRuns(line) as [AnyObject]) as! [CTRun]
@odrobnik
odrobnik / gist:2881890
Created June 6, 2012 13:34
WWDC 2012 Apps in Banner
Please help complete and sort this list. These are the icons visible in the WWDC 2012 Banner. Roughly sorted by size.
http://www.cocoanetics.com/files/WWDC2012_Banner.png
alternate, high res pictures of the Banner:
http://cdn.macrumors.com/article-new/2012/06/photo.jpg
Path - http://itunes.apple.com/us/app/path/id403639508?mt=8
Star Walk - http://itunes.apple.com/app/star-walk-guide-dastronomie/id295430577?mt=8
Instagram - http://itunes.apple.com/us/app/instagram/id389801252?mt=8
@objc protocol Refreshable
{
/// The refresh control
var refreshControl: UIRefreshControl? { get set }
/// The table view
var tableView: UITableView! { get set }
/// the function to call when the user pulls down to refresh
@objc func handleRefresh(_ sender: Any);
import Foundation
import Combine
import ProoficsSDK
import SwiftUI
class BundleViewModel: ObservableObject
{
@Published var title: String = ""
@Published var subtitle: String?
import SwiftUI
struct Modifier: Identifiable
{
let id = UUID()
@State var title: String
}
struct FastnotesSettings: View
@odrobnik
odrobnik / PlatformSpecific.swift
Created July 13, 2021 08:01
Platform-specific modifier application
import SwiftUI
struct Platform: OptionSet
{
let rawValue: Int
static let iOS = Platform(rawValue: 1<<0)
static let tvOS = Platform(rawValue: 1<<1)
static let watchOS = Platform(rawValue: 1<<2)
@odrobnik
odrobnik / ContentView.swift
Last active August 15, 2020 09:50
So far it outputs the frames of the cells, but I am stuck trying to hide the ones that are outside of the widget
import SwiftUI
struct RegularEventCell: View {
let color: Color
let title: String
let description: String?
var body: some View {
@odrobnik
odrobnik / gist:2499146
Created April 26, 2012 12:03
Convenience methods to add and animate a shadowPath
- (void)addShadowWithColor:(UIColor *)color alpha:(CGFloat)alpha radius:(CGFloat)radius offset:(CGSize)offset
{
self.layer.shadowOpacity = alpha;
self.layer.shadowRadius = radius;
self.layer.shadowOffset = offset;
if (color)
{
self.layer.shadowColor = [color CGColor];
}
@odrobnik
odrobnik / gist:2769082
Created May 22, 2012 13:32
A physical jump/bounce animation as CAKeyframeAnimation
+ (CAKeyframeAnimation *)jumpAnimation
{
// these three values are subject to experimentation
CGFloat initialMomentum = 150.0f; // positive is upwards, per sec
CGFloat gravityConstant = 250.0f; // downwards pull per sec
CGFloat dampeningFactorPerBounce = 0.6; // percent of rebound
// internal values for the calculation
CGFloat momentum = initialMomentum; // momentum starts with initial value
CGFloat positionOffset = 0; // we begin at the original position
@odrobnik
odrobnik / gist:2872435
Created June 5, 2012 03:25
Inner Shadow on Label
- (void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect:rect];
CGContextRef ctx = UIGraphicsGetCurrentContext();
NSString *fontName = self.font.fontName;
CGFloat fontSize = self.font.pointSize;
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)fontName, fontSize, NULL);