Skip to content

Instantly share code, notes, and snippets.

View oliverbarreto's full-sized avatar

Oliver Barreto oliverbarreto

View GitHub Profile
@oliverbarreto
oliverbarreto / UIView+BlurredUIView.h
Created January 12, 2014 21:18
Blur UIView Category (Credit: http://damir.me/ios7-blurring-techniques) Basically take a screenshot of a particular UIView and blur that image. But programmatically taking a screenshot in iOS 6, using renderInContext:, took too long. Fortunately iOS 7 includes a new method in UIView called drawViewHierarchyInRect:afterScreenUpdates: that does th…
// YourUIView.m (UIView)
#import "UIImage+ImageEffects.h"
-(UIImage *)blurredSnapshot
{
// Create the image context
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, self.window.screen.scale);
// There he is! The new API method
[self drawViewHierarchyInRect:self.frame afterScreenUpdates:NO];
@oliverbarreto
oliverbarreto / timer.m
Created January 4, 2014 17:24
Create a Timer or Clock with "not 100% precision" based on NSTimers
// Create an Outlet for a UIlabel on storyboard and set its text property to it...
- (void)startTimer
{
if (_timer == nil) {
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(timerTick:)
userInfo:nil
repeats:YES];
@oliverbarreto
oliverbarreto / UIFontDescriptor for Time strings
Created January 1, 2014 07:46
display the time using presentable typography, with proportionally-spaced figures and the correct hh:mm divider
display the time using presentable typography, with proportionally-spaced figures and the correct hh:mm divider
http://typographica.org/wp-content/uploads/2013/06/Customized-Font-Instance.png
@oliverbarreto
oliverbarreto / showHiddenFiles
Created December 31, 2013 08:22
Show/Hide Hidden Files OSX
# Show hidden files in Finder
# OSX 10.9 Mavericks
defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder
OSX 10.7 - !0.8
defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder
# Hide hidden files in Finder
@oliverbarreto
oliverbarreto / PulseView.m
Created December 27, 2013 16:23
Creates PulseView with a circle pulse (color and size of circle)
//
// DOBRPulseView.m
// test2
//
// Created by David Oliver Barreto Rodríguez on 27/12/13.
// Copyright (c) 2013 David Oliver Barreto Rodríguez. All rights reserved.
//
// This is much simpler if you don't draw the circle in drawRect:. Instead, set up your view to use a CAShapeLayer, like this:
#import "DOBRPulseView.h"
@oliverbarreto
oliverbarreto / setThumbnailDataFromImage.m
Created December 19, 2013 20:34
Create Thumbnail from UIImage To create a thumbnail of a image, we are going to draw a scaled-down version of the full image to an offscreen context and keep a pointer to that new image inside a object instance. You also need a place to store this thumbnail image so that it can be reloaded when the application launches again.
//Declare these 2 properties. The NSData will be a very small chunk of data that conforms to NSCoding protocol so it can be encoded with NSCoder
@property (nonatomic, strong) UIImage *thumbnail;
@property (nonatomic, strong) NSData *thumbnailData;
- (void)setThumbnailDataFromImage:(UIImage *)image
{
    CGSize origImageSize = [image size];
    // The rectangle of the thumbnail
@oliverbarreto
oliverbarreto / UIColorFromRGB(rgbValue).m
Created December 19, 2013 20:28
UIColorFromRGB(rgbValue) Normally you want to use your own color as the system color doesn’t look nice. Here is a very useful macro for setting RGB color.
// Define somewhere in a header or macro file included on prefix.psc file or put it somewhere at the beginning of AppDelegate.m and use it to create any UIColor object with whatever RGB color you want. Below is an example:
// Get colors at http://colorschemedesigner.com
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// Usage !!!
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
@oliverbarreto
oliverbarreto / titleTextAttributes.m
Created December 19, 2013 20:20
Changing the Font of Navigation Bar Title You can customize the text style by using the “titleTextAttributes” properties of the navigation bar. You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the following text attribute keys: UITextAttributeFont – Key to the …
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
@oliverbarreto
oliverbarreto / appearanceWhenContainedIn:[MyViewController class]
Created December 15, 2013 09:32
settings the appearance of cerrtain Type of controlls in a cerrtain container instead of globally settings in every container
UIPageControl *pageControl = [UIPageControl appearanceWhenContainedIn:[MyViewController class], nil];
pageControl.pageIndicatorTintColor = [UIColor whiteColor];
pageControl.currentPageIndicatorTintColor = [UIColor redColor];
pageControl.backgroundColor = [UIColor blackColor];
@oliverbarreto
oliverbarreto / search within an array
Created December 15, 2013 09:30
search for a specific element with in an NSARRAY of Objects (i.g, an specific view within views arrays)
- (void)setupPageControlAppearance
{
UIPageControl * pageControl = [[self.view.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(class = %@)", [UIPageControl class]]] lastObject];
pageControl.pageIndicatorTintColor = [UIColor grayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
}