Subclass of UITextView with syntax highlighting for iOS 5.0 not finished (just sample)

With new iOS 6.0 everyone junior iOS developer can do code editor application with syntax highlighting. Because UITextView has attribute attributedText, which has enough parameters and functionality for it.

So, I want to say, my old project does not have sense. :)

The last build shared on git hub and everyone can modify it and try to finish, because it still not completed. Still has a problem with word wrap.

Maybe someone will get something new for self. Because this project used CoreText and CoreGraphics framework.

Enjoy!

Posted in Apple, iOS, iPad, iPhone, OOP
Tagged CoreGraphics, CoreText, framework, github.com, highlighting, iOS 5.0, syntax, UITextView


Project based on DETweetComposeViewController

Facebook connection with Facebook SDK 3.0.x (last at 2 september 2012)

What is it?
DEFacebookComposeViewController is an iOS 4 compatible composer view for posting picture and message on user wall.
Looks like the Facebook Sheet in iOS 6.

How to use:
1. download and setup Facebook sdk

2. register your app on

3. replace appID in plist file. FacebookAppID and in CFBundleURLTypes

4. #import “DEFacebookComposeViewController.h”

5. use this code for posting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 DEFacebookComposeViewControllerCompletionHandler completionHandler = ^(DEFacebookComposeViewControllerResult result) {
        switch (result) {
            case DEFacebookComposeViewControllerResultCancelled:
                NSLog(@"Facebook Result: Cancelled");
                break;
            case DEFacebookComposeViewControllerResultDone:
                NSLog(@"Facebook Result: Sent");
                break;
        }
       
        [self dismissModalViewControllerAnimated:YES];
    };
   
    DEFacebookComposeViewController *facebookViewComposer = [[DEFacebookComposeViewController alloc] init];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [facebookViewComposer setInitialText:@"Look on this"];
    [facebookViewComposer addImage:[UIImage imageNamed:@"1.jpg"]];
    facebookViewComposer.completionHandler = completionHandler;
    [self presentViewController:facebookViewComposer animated:YES completion:^{ }];

Posted in iOS, iPad, iPhone
Tagged DETweetComposeViewController, Facebook, iOS 4, iOS 6, MVC, , SDK

Custom UINavigationBar

Create image for navigation background – portrait
UIImage *NavigationPortraitBackground = [[UIImage imageNamed: @"navigationbarPortrait.png"]
resizableImageWithCapInsets: UIEdgeInsetsMake(0, 0, 0, 0)];

Create image for navigation background – landscape
UIImage *NavigationLandscapeBackground = [[UIImage imageNamed: @"navigationbarLandscape.png"]
resizableImageWithCapInsets: UIEdgeInsetsMake(0, 0, 0, 0)];

Set the background image all UINavigationBars
[[UINavigationBar appearance] setBackgroundImage: NavigationPortraitBackground
forBarMetrics: UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage: NavigationLandscapeBackground
forBarMetrics: UIBarMetricsLandscapePhone];

Set attributes for buttons and title
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

[attributes setValue: [UIColor colorWithRed: 0.96f green:0.91f blue:0.64f alpha:1.00f] forKey: UITextAttributeTextColor];
[attributes setValue: [UIColor clearColor] forKey: UITextAttributeTextShadowColor];
[attributes setValue: [NSValue valueWithUIOffset: UIOffsetMake(0.0, 0.0)] forKey: UITextAttributeTextShadowOffset];
[[UIBarButtonItem appearance] setTitleTextAttributes: attributes forState: UIControlStateNormal];

[[UINavigationBar appearance] setTitleTextAttributes: attributes];

How to convert a number to the cash equivalent

NSNumberFormatter* moneyFormatter = [[[NSNumberFormatter alloc] init] autorelease];

[moneyFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];

NSString* moneyString = [moneyFormatter stringFromNumber: [NSNumber numberWithInt: 1000]];

Result: $1,000.00

NSInvocation alternative for performSelector:

This code doesn’t involve compiler flags or direct runtime calls:

1
2
3
4
5
6
SEL selector = @selector(zeroArgumentMethod);
NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig];
[invocation setSelector:selector];
[invocation setTarget:self];
[invocation invoke];

NSInvocation allows multiple arguments to be set so unlike performSelector this will work on any method.

And tip:

1
2
3
4
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.ticketTarget performSelector: self.ticketAction withObject: self];
#pragma clang diagnostic pop

Mountain Lion SVN

Good or not, but SVN moved to Xcode.app
If you want access like before in previous OS X, you should make a link to /usr/bin/svn.

1
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/svn /usr/bin/svn

Easy custom back button

1
2
3
4
UIButton* customBackButton = [UIButton buttonWithType:101];
    [customBackButton setTitle:@"Back" forState:UIControlStateNormal];
    [customBackButton setCenter:self.view.center];
    [self.view addSubview:customBackButton];

1 2 3 4 5 23