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.

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

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

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 5 Next »