Charts control with animations for iOS

Almost half year ago I’ve made this control. For one idea, but then I found that my idea does not good enough to be implemented.

It has just 2 classes VBPieChart, superclass UIView, and VBPiePiece, superclass CAShapeLayer. And really used just VBPieChart. All chart based on CALayer’s and depends to QuartzCore.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
VBPieChart *_chart = [[VBPieChart alloc] init];
[self.view addSubview:_chart];
   
[_chart setFrame:CGRectMake(10, 50, 300, 300)];
[_chart setEnableStrokeColor:YES];
_chart.length = M_PI;
_chart.startAngle = M_PI;

[_chart.layer setShadowOffset:CGSizeMake(2, 2)];
[_chart.layer setShadowRadius:3];
[_chart.layer setShadowColor:[UIColor blackColor].CGColor];
[_chart.layer setShadowOpacity:0.7];

[_chart setHoleRadiusPrecent:0.3];
NSDictionary *chartValues = @{

                       @"data one":  @{@"value":@35 },
                       @"data two":  @{@"value":@20 },
                       @"data tree":  @{@"value":@10 },
                       @"first ":  @{@"value":@40},
                       @"second": @20,
                       @"third": @40,
                       @"fourth": @10,
                       };

[_chart setChartValues:chartValues animation:YES];

chartValues contains items of chart.
1. name of piece
2. dictionary with NSNumber or parameters:
– value actually size of piece
– color, UIColor
– accent, bool value to show this item with shift

VBPieChart has 5 different types of animations.

Cocoacontrols logo

cocoapods logo

Posted in iOS
Tagged Animation, CAAnimation, CABasicAnimation, CALayer, CAShapeLayer, Chart, Charts, Control, dev, , ,

Share source code of my app

I’ve uploaded source code of my app on Github under MIT license.

App and code is free, you can do with it where you want.
If you will want add some improvements for app, I may will release them in next version ;)

Thanks

P.S.: Code not cleaned and lack of comments.

Simple way to implement multi-thread

I want show you simple way to create multi-thread calculations in few strings of code.

Simple collection of operations. But remember about blocks specifications and use proper storage type.

1
2
3
4
5
6
7
NSMutableArray *operations = [NSMutableArray array];
    for (...) {
        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
           // calculation
        }];
        [operations addObject:operation];
    }

If you don’t like blocks, you can easily make a subclass of NSOperation and overwrite main function.

Now time to create queue for operations, so just create instance of NSOperationQueue.
And in maxConcurrentOperationCount property you need setup proper value. For example 2, if you want to use just 2 concurrent threads for your calculations and continue in normal state with others operations in another threads.
In this case waitUntilFinished should be NO.

But if you want to use max threads of CPU, setup NSOperationQueueDefaultMaxConcurrentOperationCount to maxConcurrentOperationCount and YES to waitUntilFinished. Like in example below:

1
2
3
4
5
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue setMaxConcurrentOperationCount:....];
    [queue addOperations:operations waitUntilFinished:YES];
    [queue waitUntilAllOperationsAreFinished];
    [operations removeAllObjects];

If this is set, it will choose an appropriate value based on the number of available processors and other relevant factors.

1
2
3
enum {
  NSOperationQueueDefaultMaxConcurrentOperationCount = -1
};

NSOperationQueueDefaultMaxConcurrentOperationCount: The default maximum number of operations is determined dynamically by the NSOperationQueue object based on current system conditions.

That it! It’s so simple today.

How to extend existing method

With blocks it’s more easy if you need extend your method. But if you will need extend some method of another class, not yours, and you will not be able to get the sources then this solution for you. (And if you will not be able or does not have any reason for creating a subclass)

1. You need create a category of class

2. import runtime in implementation file (.m)

1
#import

3. implement your method inside category, for example :

1
2
3
4
5
6
7
8
9
- (void) extend_method {

// your code

//  here will be performed the original method
    [self extend_method];
   
// your code
}

It looks like this method has recursive calls itself, but it’s not true. Look next step

4. add method for replace (you can use +initialize or +load)

1
2
3
4
5
+ (void) initialize {
    Method original = class_getInstanceMethod(self, @selector(method));
    Method replacement = class_getInstanceMethod(self, @selector(extend_method));
    method_exchangeImplementations(original, replacement);
}

Done!

How to add Push Notifications to your iOS application

Hi guys!

Welcome to 5 Min Guide about how to integrate Push Notifications into your application.

Push notification allows App to notify you of new messages or events without need to open the application in fact, they are similar to usual text message which appears like a popup on your screen with a sound.

This is a great way for apps to interact with us in the background, whether it is a game that notifies us of some event occurring in our game world or simple mail application that is beeping when a new message appears in our inbox.

As you know, Push Notifications require server side (3rd party server), e.g. for storing device tokens and for sending push notifications:

Some people still have problems with this – they  think that they should develop this server by themself, lots of hard work, time, money, etc.

But stop! We live in the mobile era! All this hard work is already done by another people. All you need – just use ready made products.  Do not reinvent the wheel!

And, one such product is QuickBlox. QuickBlox is a cloud hosted platform to simplify your mobile app backend development. It has lots of Great Features for any platform such Push Notifications, Location, Content, Ratings features, Social integration, Chat and lots of other mobile killer features!

Today we are going to talk about how to integrate one of these great feature to your iOS mobile application – Push Notifications, provided by QuickBlox Messages module. So, let’s start!

Continue reading

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];

1 2 3 4 Next »