Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
@jeksys
jeksys / gist:2936420
Created June 15, 2012 13:15
custom UINavigationBar
UIImage *backgroundImage = [UIImage imageNamed:@"UI_navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:backgroundImage
forBarMetrics:UIBarMetricsDefault];
UIImage *backButton = [[UIImage imageNamed:@"UI_backbutton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,0,0,0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateHighlighted
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
@jeksys
jeksys / gist:2936429
Created June 15, 2012 13:19
UIToolBar backgrund image
UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
@jeksys
jeksys / gist:2956352
Created June 19, 2012 20:27
UISearchBar custom background
for (id img in searchBar.subviews) {
if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[img removeFromSuperview];
}
}
[searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"UI_searchbar.png"] forState:UIControlStateNormal];
searchView.backgroundColor = [UIColor clearColor];
for (UIView *subview in [[searchBar.subviews objectAtIndex:0] subviews]) {
subview.alpha = 0.0;
subview.backgroundColor = [UIColor clearColor];
@jeksys
jeksys / gist:3136241
Created July 18, 2012 13:33
FizzBuzz
int main() {
for( int i=1; i<=100; i++)
{
if(i%3==0)
printf("Fizz");
if(i%5==0)
printf("Buzz");
if(i%3!=0 && i%5!=0)
printf("%d",i);
@jeksys
jeksys / gist:3747387
Created September 19, 2012 02:53
dispatch_after
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
@jeksys
jeksys / gist:3953709
Created October 25, 2012 16:09
Render a layer to an image with scalefactor
dispatch_async(dispatch_get_main_queue(), ^{
previewToSave = nil;
CGSize screenSize = self.view.bounds.size;
float scaleFactor = 0.2;
const size_t originalWidth = screenSize.width * scaleFactor;
const size_t originalHeight = screenSize.height * scaleFactor;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(nil, originalWidth, originalHeight, 8, 4*(int)originalWidth, colorSpaceRef, kCGImageAlphaPremultipliedLast);
if (ctx != nil) {
@jeksys
jeksys / gist:3953710
Created October 25, 2012 16:09
Render a layer to an image with scalefactor
dispatch_async(dispatch_get_main_queue(), ^{
previewToSave = nil;
CGSize screenSize = self.view.bounds.size;
float scaleFactor = 0.2;
const size_t originalWidth = screenSize.width * scaleFactor;
const size_t originalHeight = screenSize.height * scaleFactor;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(nil, originalWidth, originalHeight, 8, 4*(int)originalWidth, colorSpaceRef, kCGImageAlphaPremultipliedLast);
if (ctx != nil) {
@jeksys
jeksys / gist:4066478
Created November 13, 2012 15:50
iOS\Resource\Property List template
<plist version="1.0">
<array>
<dict>
<key>category</key> <string>classic</string>
<key>quote</key> <string>Frankly my dear, I don't give a dam.</string>
<key>source</key> <string>Gone with the wind</string>
</dict>
@jeksys
jeksys / gist:4088742
Created November 16, 2012 16:32
webView PDF
NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
@jeksys
jeksys / gist:8c792baeafa13fe4f01a
Created January 23, 2015 02:56
Swift delay func
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}