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.
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 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 :)
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];
What's the easiest way to draw an inner shadow in a UILabel, without using images?
I know you can use shadowColor and shadowOffset for drop shadows, but I didn't see any such properties for inner shadows.
Check out FXLabel. I've been using it recently and it works great.
https://github.com/nicklockwood/FXLabel
I do not believe there is any easy way to accomplish this appearance. You will either need to use an image or a custom view that draws the shadow.
I would use your favorite image editor to make an image of the inner shadow composited against transparency (or a color if you need it) and load it into a stretchable UIImage. For example here is an inner shadow image (17px x 17px):
You can load it like this:
UIImage* innerShadow = [ [ UIImage imageNamed: "innershadow.png" ]
stretchableImageWithLeftCapWidth: 8 topCapHeight: 8 ];
UIImageView* innerShadowView = [ [ [ UIImageView alloc ] initWithImage: innerShadow ]
autorelease ];
myLabel.backgroundColor = [ UIColor clearColor ];
Then place innerShadowView behind the label. You could generate the image programmatically as well if you wanted to avoid an image resource.
** Update based on comments follows **
Ah, based on your latest comment the effect you are looking for is completely different than the picture in the earlier comment.
In this case you will have to make a UILabel subclass and do your own drawing to composite the effect you are looking for. Take a look at this answer for how to composite the inner shadow effect.
What you mean by any such properties for inner shadows.
shadowOffset is the option to set the shadows (vertical or horizontal shadow) of the UILabel.
I do not know but this answer may be long to implement.
I want to create shadow of barplot what should I do . I use core-plot framwork
I dont know abt giving exactly shadow effect on individual bar. But similar to shadow effect, You can try using 'tubular' bar rather than flat bars. +(CPBarPlot *)tubularBarPlotWithColor:(CPColor *)color horizontalBars:(BOOL)horizontal
something like this
barPlot = [CPBarPlot tubularBarPlotWithColor:[CPColor greenColor] horizontalBars:NO];
[barGraph addPlot:barPlot toPlotSpace:barPlotSpace];
Hope this helps.