Skip to content

Instantly share code, notes, and snippets.

View dimitris-c's full-sized avatar

Dimitris C. dimitris-c

View GitHub Profile
@dimitris-c
dimitris-c / gist:42471fe9289e803046cd
Created August 26, 2014 15:14
Split an array in half
+ (NSArray *)splitArrayIntoHalf:(NSArray *)originalData {
NSRange firstHalfRange;
firstHalfRange.location = 0;
firstHalfRange.length = originalData.count / 2;
NSArray *firstHalfArray = [originalData subarrayWithRange:firstHalfRange];
NSRange secondHalfRange;
secondHalfRange.location = firstHalfRange.length;
@dimitris-c
dimitris-c / gist:17b35c3bbb4cebd3e3df
Created September 11, 2014 15:34
Disable touches behind a UIVIew
@interface PassthroughView : UIView
@end
@implementation PassthroughView
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *view in self.subviews) {
if (!view.hidden && view.alpha > 0 && view.userInteractionEnabled && [view pointInside:[self convertPoint:point toView:view] withEvent:event])
return YES;
}
return NO;
http://charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state/
I recently created a custom UITableViewCell with a UIButton as a subview. Pretty standard except that the highlight state of the button was only activated if you held your finger on the button for more than some fraction of a second. The solution is quite straight forward but is subtle enough to justify a quick blog post.
Table view cells are displayed using a UITableView which is a subclass of UIScrollView and as such inherits the ability to scroll. A scroll view intercepts touch events and has a short delay to check if the touch event is part of a scroll gesture. If it isn’t then the touch event is passed onto the corresponding view. That explains the delay in the button highlight state.
We can remove the delay by setting UIScrollView.delaysContentTouches = NO. A side effect of this change is that scroll gestures cannot start from the buttons. Depending on how big your buttons are this might not be ideal. The wo
@dimitris-c
dimitris-c / index.html
Last active August 29, 2015 14:13
mymqwm
<h1>ARGB color to Objective-C UIColor</h1><br>
<div id="input-bar">
<div id="hexBar">
<input type="text" id="argbText"></input>
</div>
<div id="button">
<input type="button" id="convertButton" value="Convert" onclick="argb2UIColor()"></input>
</div>
</div>
<div id="output-bar">
http://stackoverflow.com/questions/24912704/xcodebuild-running-tests-headless
http://stackoverflow.com/questions/9476131/is-there-a-way-to-remove-the-authorization-prompt-from-command-line-instances-of
@dimitris-c
dimitris-c / UINavigationControllerΕxtensions.swift
Last active July 5, 2017 16:45
Allow childViewControllers to change statusBarStyle
extension UINavigationController {
override open var childViewControllerForStatusBarStyle: UIViewController? {
return self.topViewController
}
override open var childViewControllerForStatusBarHidden: UIViewController? {
return self.topViewController
}
@dimitris-c
dimitris-c / gist:c005190beded8a75c2cd6d4f3ee929da
Last active February 13, 2018 14:49
CenterCellCollectionViewFlowLayout
class CenterCellCollectionViewFlowLayout: UICollectionViewFlowLayout {
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
guard let collectionView = self.collectionView else {
return super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity)
}
if collectionView.numberOfItems(inSection: 0) == 0 {
return super.targetContentOffset(forProposedContentOffset: proposedContentOffset)
}
import CoreLocation
enum LocationAuthorizationStatus {
case always
case whenInUse
}
final class LocationManager: NSObject, CLLocationManagerDelegate {
typealias LocationAuthorizationCompletion = (CLAuthorizationStatus) -> Void
@dimitris-c
dimitris-c / MiniAutolayoutKit.swift
Created September 27, 2017 15:49
MiniAutolayoutKit — A super mini auto layout kit for faster programmatic layout
import UIKit
extension UIView {
public func prepareForAutolayout() {
translatesAutoresizingMaskIntoConstraints = false
}
public func autopin(constant: CGFloat = 0) {
autopin(.top, constant: constant)
@dimitris-c
dimitris-c / gist:8d32a81fe711f17665f113fce78d7c15
Last active November 6, 2017 14:26
A UILabel subclass that provides extra padding for background
class EdgesLabel: UILabel {
var edgeInsets: UIEdgeInsets = .zero {
didSet {
layoutIfNeeded()
}
}
override func drawText(in rect: CGRect) {
super.drawText(in: UIEdgeInsetsInsetRect(rect, edgeInsets))