Skip to content

Instantly share code, notes, and snippets.

@bleft
bleft / gist:5134145
Created March 11, 2013 13:17
switch background color responding to the BOOL loggedIn.
self.view.backgroundColor = loggedIn ? [UIColor greenColor] : [UIColor redColor];
@bleft
bleft / gist:5590171
Created May 16, 2013 08:05
pulsing animation. Put two UIImageViews on a view for low and highlighted. Animate the highlighted for pulsing. To stop animation remove animation from layer. Needs QuartzCore.Framework.
- (void)startAnimation
{
self.imageViewHigh.hidden = NO;
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration = 1.0f;
theAnimation.repeatCount = HUGE_VALF;
theAnimation.autoreverses = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
theAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[self.imageViewHigh.layer addAnimation:theAnimation forKey:@"animateOpacity"];
@bleft
bleft / gist:5926865
Created July 4, 2013 11:12
UIScrollView and UIPageControl set Page scrollView, set Page on Page controller
static CGSize scrollSize; // set on viewDidLoad
- (CGRect)frameForPosition:(int)pos
{
float x = pos * scrollSize.width;
float y = 0;
float width = scrollSize.width;
float height = scrollSize.height;
return CGRectMake (x, y, width, height);
@bleft
bleft / gist:7038550
Created October 18, 2013 08:47
git alias for better log
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
@bleft
bleft / NSMutableString+Utils.m
Created March 11, 2014 12:16
NSMutableString: appendStringOrEmpty
- (void)appendStringOrEmpty:(NSString*)string{
if (string) {
[self appendString:string];
} else {
[self appendString:@""];
}
}
@bleft
bleft / imageFromView.m
Last active August 29, 2015 13:59
UIImage from View
+ (UIImage *)imageFromView:(UIView *)view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 2.0);
} else {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
}
} else {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
@bleft
bleft / sharedInstance.m
Created July 3, 2014 12:33
create singleton dispatch_once_t
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@bleft
bleft / maxNumbersOfLines.m
Created July 22, 2014 14:40
set maximum number of lines on UITextView
// the following snippet sets the number of lines to 1
myTextView.attributedText = [[NSAttributedStringalloc] initWithString:@"my too long text"];
myTextView.textContainer.maximumNumberOfLines = 1;
myTextView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
@bleft
bleft / gist:c9ae29f3cd51ea439c63
Created September 24, 2014 14:34
colors in terminal: .bash_profile
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
@bleft
bleft / roundView.swift
Created October 17, 2014 10:46
Make round UIView
let layer = view.layer
layer.cornerRadius = CGRectGetWidth(mapView.bounds) / 2
layer.borderWidth = 1
layer.masksToBounds = true