I need to implement bubble chart in an iPad application with each bubble having user interaction (touch event) to navigate to a detailed view.
Is there any framework or a way to do so (like bargraph, piechart, linegraph using coreplot)??
I tried implementing manually even using CGContextRef for each bubble as below
CGContextRef c = UIGraphicsGetCurrentContext();
UIColor *grayColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
[grayColor set];
CGRect rectangle = CGRectMake(xaxis+2,yaxis+2,size-4,size-4);
CGContextSetLineWidth(c,4);
CGContextStrokeEllipseInRect(c, rectangle);
CGContextAddEllipseInRect(c, rectangle);
CGContextSetFillColorWithColor(c, [bubbleColor CGColor]);
CGContextFillPath(c);
but unable to crop the edges from having user interaction i.e, touch event (since these bubbles are circles inscribed in UIView's).
Thanks in Advance
You can use a scatter plot for this. Implement the -symbolForScatterPlot:recordIndex: datasource method to provide a custom plot symbol for each plot point. Vary the size, shape, fill, etc., of the symbols as desired based on the data.
Try this and this. Also, you could try OBShapedButton with your images. Hope this helps :)
Related
I was very surprised to not find the answer on Stackoverflow to this one.
I have a vector path in pdf format, like Safari or the Mac App Store apps usually use as image icons.
Now, I'd like to specify the fill-color and a custom shadow in code, rather than making images and exporting them. I didn't figure out how to do this.
The shadow works, however the fill color does not.
Can anyone tell me how to do this?
Current Code
[NSGraphicsContext saveGraphicsState];
{
// Has no effect
[[NSColor colorWithCalibratedRed:0.92f green:0.97f blue:0.98f alpha:1.00f] setFill];
// Neither has this
[[NSColor colorWithCalibratedRed:0.92f green:0.97f blue:0.98f alpha:1.00f] set];
NSShadow *shadow = [NSShadow new];
[shadow setShadowOffset:NSMakeSize(0, -1)];
[shadow setShadowColor:[NSColor blackColor]];
[shadow setShadowBlurRadius:3.0];
[shadow set];
[image drawInRect:imgRect
fromRect:NSZeroRect
operation:NSCompositeXOR
fraction:1.0
respectFlipped:YES
hints:nil];
}
[NSGraphicsContext restoreGraphicsState];
In terms of calling drawInRect:... the image "is what it is". Setting the fill and stroke will effect only primitive operations. A good way to think about this is to realize that all images, vector or raster, have to behave the same way; It would be weird for the current fill color that's set on the context to affect the drawing of a raster-based image, right? Same idea -- the image is the image. The vector image might also have multiple paths in it, each with different fills. It wouldn't make sense for those to be overridden by the fill color set on the context either.
The shadow works regardless because it's effectively a compositing operation; Drawing a given image with a given shadow setting produces the same shadow whether the image was raster-based or the vector equivalent thereof.
In short, if you want to change the contents of the image, you're going to have to write the code to extract the vectors from the image and then draw them as primitives.
Alternately, if all you want is to fill any filled areas with the color, you could use the vector image to create a mask on the context, then you could set the color
on the context, and fill. That might produce the desired effect.
I need to make a project where I will draw some graphics on the screen, its about 25 separated bars, I've done it with UIView, but unfortunately not all devices can handle this job, because there is a 25x25 matrix of squares of UIViews, they are updating its color and alpha in 0.04 seconds, and its really takes a lot of memory to draw it like this, can someone please help with a purpose, how can it all be done faster for memory managing, and if its possible to control its components like alpha or background color for an object. Thanks in advance
What I understand is that you use 25 subviews for each bar. You can already optimize that and make each bar a single UIView. You can make a custom subclass of UIView that we will call BarView and override its drawRect method to draw the 25 squares of the bar.
Edit
Assuming you have an array bars that contains 25 bars (of type Bar). Each bar contains an array squares of 25 squares (of type Square).
- (void)drawRect:(CGRect)rect
{
CGContextRef *ctx = UIGraphicsGetCurrentContext();
for (Bar *bar in self.bars) {
for (Square *square in bar.squares) {
CGContextSetFillColorWithColor(ctx, square.color.CGColor);
CGContextFillRect(ctx, square.frame);
}
}
}
Bar and Square do not subclass UIView, they are simple NSObjects.
Finally note that this code is only an example and that there are possibilities to further improve performance.
Go for OpenGL. It has very efficient 2D drawing mechanism as well.
You might want to switch to a Core Animation based drawing approach as proposed in this answer. The idea is to draw as few things as possible using Core Graphics. Instead you create layers for all your independently animating graphical elements and animate layer properties.
To draw bars you could create a layer and set its backgroundColor and bounds/center properties to animate its size and appearance.
I need to add shadow to all side to a label.It will look like this.
How Can I do this?Please help.I am using shadowOffset ,but it is not giving shadow in all side.Please help.
Assuming you're asking how to add the white outline, you can't do that with a plain UILabel. You need to draw the text using Core Graphics (aka Quartz 2D). Something like this:
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextSaveGState(gc); {
CGContextSetTextDrawingMode(gc, kCGTextFillStroke);
CGContextSetFillColorWithColor(gc, UIColor.blueColor.CGColor);
CGContextSetStrokeColorWithColor(gc, UIColor.whiteColor.CGColor);
CGContextSetLineJoin(gc, kCGLineJoinRound);
CGContextSetLineWidth(gc, 2);
CGContextSetShadowWithColor(gc, CGSizeMake(-1, 2), 2, UIColor.blackColor.CGColor);
[#"Card" drawAtPoint:CGPointMake(0, 20) withFont:[UIFont systemFontOfSize:18]];
} CGContextRestoreGState(gc);
I have come across a project by nicklockwood on gitHub. It improves upon the standard UILabel by providing a subclass that supports soft shadows, inner shadow and gradient fill, and which can easily be used in place of any standard UILabel.Have a look at it.It will be useful to you.
I want to implement below chart like structure.
Explanation:
1. Each block should be clickable.
2. If the block is selected, it will be highlighted(i.e. Red block in figure).
I initially google for this but was unable to find. What should be "Drawing logic" corresponding to this with animation?Thanx in advance.
I think you need to use MCSegmentedControl.
You can get it from here.
Generally speaking, I'd have an image for the outline with a transparent middle, then dynamically create colored blocks behind it of the appropriate colors, with dynamic labels. The highlighting is a little tricky, but could be done with a set of image overlays. One could also try to shrink and expand fixed images for the bars/highlighting, but iPhone scales images poorly.
(Will it always be 4 blocks? There are a couple of other ways to manage it using fixed-size images overlaying each other.)
Maybe you should look into using CALayer for this?
U need to implement this type of logic using button. Just scale button width according to percentage.
And to make round rect button like appearance use the code below and don't forget to import quartz-core framework in class file.
And to scale first and last button as you need some overlap from nearby button.
btn.layer.cornerRadius = 8.0;
btn.layer.borderWidth = 0.5;
btn.layer.borderColor = [[UIColor blackColor] CGColor];
I have a1.png image.
I want to apply a color effect on that image.
By "apply a colour" I mean a foreground color with alpha < 1.
Does anyone have a solution?
I think you are looking for GLImageProcessing sample code
I haven't get solution for applying UIColor to existing image.
One alternative way is that instead of applying color to an image you can take a View and apply color to the view.
UIColor *color = [del color];
[perceptView setBackgroundColor:[color colorWithAlphaComponent:0.5]];
[perceptView setNeedsDisplay];