Skip to content

Instantly share code, notes, and snippets.

View jeffbailey's full-sized avatar

Jeff Bailey jeffbailey

View GitHub Profile
@jeffbailey
jeffbailey / Sparkle.swift
Created December 21, 2022 18:33 — forked from UnderscoreDavidSmith/Sparkle.swift
Sparkle Effect in SwiftUI
@available(iOS 15.0, *)
struct TwinkleView:View {
private func position(in proxy: GeometryProxy, sparkle:Sparkle) -> CGPoint {
let radius = min(proxy.size.width, proxy.size.height) / 2.0
let drawnRadius = (radius - 5) * sparkle.position.x
let angle = Double.pi * 2.0 * sparkle.position.y
let x = proxy.size.width * 0.5 + drawnRadius * cos(angle)
let y = proxy.size.height * 0.5 + drawnRadius * sin(angle)
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct CrossEffectDemo: View {
let animationDuration: Double = 2
let images = ["photo1", "photo2", "photo3", "photo4"]
@State private var idx = 0
CFNETWORK_DIAGNOSTICS = 1 // NSURLSession debugging
Thanks to http://radex.io/watch/hyphenation/?utm_campaign=iOS%2BDev%2BWeekly&utm_source=iOS_Dev_Weekly_Issue_200
extension WKInterfaceLabel {
func setHyphenatedText(text: String) {
let style = NSMutableParagraphStyle()
style.hyphenationFactor = 1
let attributes = [NSParagraphStyleAttributeName: style]
setAttributedText(NSAttributedString(string: text, attributes: attributes))
}
@jeffbailey
jeffbailey / isViewHidden
Created December 30, 2014 16:30
Utility method to see if the UIView or one of its superviews is hidden
- (BOOL)isViewHidden:(UIView *)view
{
if (view.hidden==YES || view.superview==nil) {
return YES;
}
return [self isViewHidden:view.superview];
}
@jeffbailey
jeffbailey / ShareExample
Created December 17, 2014 18:38
Example of sharing a PDF in iOS 8
NSArray* itemsToShare = [NSArray arrayWithObjects:pdfData, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard]; //or whichever you don't need
activityVC.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityVC animated:YES completion:nil];
@jeffbailey
jeffbailey / Podfile32Bit
Created October 16, 2014 12:29
How to build cocoapods library for 32 bit architecture
# Remove 64-bit build architecture from Pods targets
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |configuration|
target.build_settings(configuration.name)['ARCHS'] = '$(ARCHS_STANDARD_32_BIT)'
end
end
end
@jeffbailey
jeffbailey / iOS8ResizableTableViewCells
Created August 13, 2014 17:46
iOS 8 Resizable Table View Cells and multiline labels
A good blog post and sample project is at:
https://github.com/kharrison/CodeExamples/tree/master/SelfSize
UITableViewController Methods:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.rowHeight = UITableViewAutomaticDimension;
@jeffbailey
jeffbailey / CreateAndCenterButtonWithAutoLayout
Created August 10, 2014 20:51
Create and center a button using Autolayout
self.insertTextButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.insertTextButton setTitle:@"Press Me" forState:UIControlStateNormal];
[self.insertTextButton sizeToFit];
self.insertTextButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.insertTextButton addTarget:self action:@selector(insertText) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.insertTextButton];
[self.view addConstraint: [NSLayoutConstraint constraintWithItem:self.insertTextButton
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
@jeffbailey
jeffbailey / Multiline UILabel
Created July 28, 2014 20:11
Multiline UILabel in Interface Builder
// The first two lines can be set in Interface builder
self.titleLabel.numberOfLines = 0;
self.titleLabel.lineBreakMode:NSLineBreakByWordWrapping;
[self.titleLabel setPreferredMaxLayoutWidth:self.frame.size.width-50];
// Also in IB, set a constraint on the label so the height it >= the height of a single line