Skip to content

Instantly share code, notes, and snippets.

View jacksonfdam's full-sized avatar
💻
Coding...

Jackson F. de A. Mafra jacksonfdam

💻
Coding...
View GitHub Profile
@jacksonfdam
jacksonfdam / gist:2820350
Created May 28, 2012 18:06
Custom Font Support
iOS 3.2 and later support this. Straight from the What's New in iPhone OS 3.2 doc:
Custom Font Support
Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file. The value of this key is an array of strings identifying the font files in the application’s bundle. When the system sees the key, it loads the specified fonts and makes them available to the application.
Once the fonts have been set in the Info.plist, you can use your custom fonts as any other font in IB or programatically.
There is an ongoing thread on Apple Developer Forums:
https://devforums.apple.com/thread/37824 (login required)
@jacksonfdam
jacksonfdam / gist:2836339
Created May 30, 2012 13:31
Wordpress - Insert a post via code
<?php
// functions.php
function clippingContentInsertion() {
for ($x = 0; $x < 100; $x++):
$data = array(
'post_status' => 'publish',
'post_type' => 'clipping',
'post_author' => 1,
@jacksonfdam
jacksonfdam / gist:2852794
Created June 1, 2012 15:05
Streatch image with stretchableImageWithLeftCapWidth: topCapHeight:
+ (UIImage*)greenBubble
{
if (sGreenBubble == nil) {
UIImage *i = [UIImage imageNamed:@"Balloon_1.png"];
sGreenBubble = [[i stretchableImageWithLeftCapWidth:15 topCapHeight:13] retain];
}
return sGreenBubble;
}
+ (UIImage*)grayBubble
@jacksonfdam
jacksonfdam / gist:2852802
Created June 1, 2012 15:06
Custom NavigationItem
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
UIImage *navBarImage = [UIImage imageNamed:@"imgnavbar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
UIImage *barButton = [[UIImage imageNamed:@"navbar-icon.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
UIImage *backButton = [[UIImage imageNamed:@"back-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 14, -1, 4)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
@jacksonfdam
jacksonfdam / gist:2852920
Created June 1, 2012 15:21
Using flashScrollIndicators with UIWebView
for (id subView in [webView subviews]) {
if ([subView respondsToSelector:@selector(flashScrollIndicators)]) {
[subView flashScrollIndicators];
}
}
@jacksonfdam
jacksonfdam / gist:2852924
Created June 1, 2012 15:22
Removing the UIWebView background shadows
if ([[webView subviews] count] > 0) {
// hide the shadows
for (UIView* shadowView in [[[webView subviews] objectAtIndex:0] subviews]) {
[shadowView setHidden:YES];
}
// show the content
[[[[[webView subviews] objectAtIndex:0] subviews] lastObject] setHidden:NO];
}
webView.backgroundColor = [UIColor whiteColor];
@jacksonfdam
jacksonfdam / gist:2852928
Created June 1, 2012 15:23
Preloading the UIWebView content before displaying
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// check indexPath...
myWebView = [[MyWebViewController alloc] init];
myWebView.delegate = self;
[myWebView preLoadView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self.navigationController pushViewController:myWebView animated:YES];
[myWebView release];
@jacksonfdam
jacksonfdam / gist:2852960
Created June 1, 2012 15:28
NSClassFromString to Check for Class Availability
Class TweetViewController = NSClassFromString(@"TWTweetComposeViewController");
if (TweetViewController != nil)
{
...
}
else
{
...
}
@jacksonfdam
jacksonfdam / gist:2853004
Created June 1, 2012 15:35
Delete All Files in Documents Directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
{
NSLog(@"Path: %@", [paths objectAtIndex:0]);
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
// Remove all files in the documents directory
BOOL deleted = [fileManager removeItemAtPath:[paths objectAtIndex:0] error:&error];
@jacksonfdam
jacksonfdam / gist:2853019
Created June 1, 2012 15:36
UIColor from hex
+ (UIColor* ) colorWithHex:(int)color {
float red = (color & 0xff000000) >> 24;
float green = (color & 0x00ff0000) >> 16;
float blue = (color & 0x0000ff00) >> 8;
float alpha = (color & 0x000000ff);
return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha/255.0];
}