CLColorPicker: User friendly color picker for Mac apps

Here is implementation of color picker control which is similar to one that used in original Mac applications like Numbers, Pages, Keynote. Original one has lots of small pictures. This control based on NSSegmentedControl and have numbers of useful thinks to know, so it’s not just implementation but also good place to look:
- how to subclass NSSegmentedCell
- how is working NSTrackingArea
- create NSPopover

CLColorPicker

Easy to use. Just create view and add on your master view:

1
2
CLColorPicker *control = [CLColorPicker alloc] initWithFrame:NSMakeRect(100,100, 70, 24)];
[self.view addSubview:control];

To get selected color:

1
NSColor *color = control.selectedColor;

Or set color:

1
[control setSelectedColor:yourColor];

command atos

Very useful command `atos`.

A stripped, optimized version of Sketch was built as an x86_64 position-independent executable (PIE)
into /BuildProducts/Release. Full debug symbol information is available in Sketch.app.dSYM, which sits
alongside Sketch.app. When Sketch.app was run, the Sketch binary (which was built at 0×100000000) was
loaded at 0x10acde000. Running ‘sample Sketch’ showed 3 addresses that we want to get symbol informa-tion information
tion for — 0x10acea1d3, 0x10ace4bea, and 0x10ace4b7a.

First notice that the .dSYM is next to the .app:

% ls -1 /BuildProducts/Release/
Sketch.app
Sketch.app.dSYM

Now, to symbolicate, we run atos with the -o flag specifying the path to the actual Sketch executable
(not the .app wrapper), the -arch x86_64 flag, and the -l _x1_acde___ flag to specify the load address.

% atos -o /BuildProducts/Release/Sketch.app/Contents/MacOS/Sketch -arch x86_64 -l 0x10acde000 0x10acea1d3 0x10ace4bea 0x10ace4b7a
-[SKTGraphicView drawRect:] (in Sketch) (SKTGraphicView.m:445)
-[SKTGraphic drawHandlesInView:] (in Sketch) (NSGeometry.h:110)
-[SKTGraphic drawHandleInView:atPoint:] (in Sketch) (SKTGraphic.m:490)

Source

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.

Configuring and compiling VTK 6.1 on Mac OS X 10.9.2 + simple example of VTK usage

Hello. In this short post I will explain how to build static libraries of VTK.
Main reason why it needs: Because official “How to” has just 2 lines without any explanations. And by default will be builded dynamic libraries. With which I had a problem like link to vtkCocoaGLView was not found, but it actually was in a library.

Let’s start. You will need CMake to build and VTK sources.

- Launch CMake from your Application folder. In main menu go to “Tool” -> “Install for Command Line Use”, in case if you did not install yet.
- Unpack VTK to some directory, working place.
- Enter to VTK directory and create directory with name build

Now you can configure and generate makefile or Xcode project file from console or User interface of CMake application.
If you would like to build with makefile in terminal go to next steps, if not jump to Build with Xcode section.
Continue reading

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.

You need to know something …

Objective-c
Timing for different conditions in 2147483647 (max int) iterations cycle:

1
2
3
4
5
6
7
8
9
2013-05-30 15:09:26.719 self[10228:707] object is not nil 3.580853 sec
2013-05-30 15:09:38.837 self[10228:707] object check bool 12.118355 sec
2013-05-30 15:09:51.900 self[10228:707] object check BOOL 13.061721 sec
2013-05-30 15:10:03.228 self[10228:707] object has object 11.327167 sec
2013-05-30 15:10:13.916 self[10228:707] object has object which is not nil 10.687253 sec
2013-05-30 15:10:31.121 self[10228:707] object has 3 level of objects 17.203815 sec
2013-05-30 15:10:51.921 self[10228:707] object isKindOfClass 20.798705 sec
2013-05-30 15:10:56.361 self[10228:707] perform block 4.439318 sec
2013-05-30 15:11:02.305 self[10228:707] block is available and perform then 5.943721 sec

So, isKindOfClass will slow down your app much as possible! ;)

Continue reading

Free application for iPad

Essential Skeleton iconEssential Skeleton allows users to rotate the model at any angle, view bones in isolation, listen to audio pronunciations of bones, annotate & share media and quiz yourself on what you have learned. This app is being offered free to demonstrate the groundbreaking 3D technology and innovative design inherent in Essential Anatomy.

Download Essential Skeleton

1 2 3 16 Next »