Skip to content

Instantly share code, notes, and snippets.

View iosappdeveloper's full-sized avatar

iosappdeveloper

View GitHub Profile
@iosappdeveloper
iosappdeveloper / UIControl+EventPublisher.swift
Created January 1, 2021 22:01
Supports handling of events on a UIControl using Combine framework
extension UIControl {
struct EventPublisher: Publisher {
typealias Output = Void
typealias Failure = Never
fileprivate var control: UIControl
fileprivate var event: Event
func receive<S: Subscriber>(subscriber: S) where S.Input == Output, S.Failure == Failure {
let subscription = EventSubscription<S>()
@iosappdeveloper
iosappdeveloper / WKWebViewEventListener.swift
Last active November 17, 2023 15:56
Add event listener from iOS code and then get callback in native code
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
print("\(#function): \(message)")
}
func setupSubViews() {
let configurations = WKWebViewConfiguration()
let controller = WKUserContentController()
let myEventScriptString =
"""
var elements = document.getElementsByClassName('button');
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="button.css">
<style>
.centered {
padding: 15px;
text-align: center;
}
</style>
@iosappdeveloper
iosappdeveloper / ViewController.m
Created September 17, 2015 13:23
UINavigationController "Back" button - custom handling
// Navigation BACK Button - custom
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Backk" style:(UIBarButtonItemStylePlain) target:self action:@selector(back:)];
self.navigationItem.backBarButtonItem = backButtonItem;
self.navigationItem.hidesBackButton = NO;
}
- (void)back:(id)button {
@iosappdeveloper
iosappdeveloper / gist:f7beaf293ceb6fbc70e6
Created September 29, 2014 00:20
UIView border layer color with shadow animation
CALayer *layer = self.downloadContainerView.layer;
layer.shadowOffset = CGSizeMake(2, 2);
layer.shadowColor = [UIColor blackColor].CGColor;
layer.shadowRadius = 4.0f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
CABasicAnimation *color = [CABasicAnimation animationWithKeyPath:@"borderColor"];
color.fromValue = (id)[UIColor redColor].CGColor;
color.toValue = (id)[UIColor lightGrayColor].CGColor;
@iosappdeveloper
iosappdeveloper / gist:c040224c4861aef1641d
Created August 14, 2014 16:01
Dynamic table view cell height using auto layout
// $$$ Not self tested yet but accepted answer at http://stackoverflow.com/questions/25306299/how-to-make-autosizeheight-uitableviewcell
// For iOS 6 and 7. After iOS 8, it's claimed to be automatic.
@property (nonatomic, strong) CustomCell *layoutTableViewCell;
UINib *cellNib = [UINib nibWithNibName:CustomCellNibName bundle:nil];
self.layoutTableViewCell = [[cellNib instantiateWithOwner:nil options:nil] objectAtIndex:0];