I want to create an image where the pattern fades out closer to the middle.
So the as it goes from middle of the image to the sides the pattern get more opacity.
The attached image is what I have so far. Basically instead of blue colour I want to have hexagons fading out as it gets closer to the middle.
Thank you!
You want to create the pattern on a layer, then apply a "gradient fade" effect (last one on the list) on that layer. Set the gradient to "radial" and you're golden.
Related
I'm tying to draw two different shadows on some text to create an embossed effect. Here's the portion of my drawInRect where I draw the text with the first shadow (all the variables used are already defined):
CGContextSetShadowWithColor(context, textInnerShadowOffset, textInnerShadowBlurRadius, textInnerShadowColor.CGColor);
[textColor setFill];
[self.text drawInRect:rect withFont:self.font lineBreakMode:self.lineBreakMode alignment:self.textAlignment];
But now I'm faced with the problem of drawing the second shadow. I assume I'll need to change the shadow and draw the text again, but I need to do so without adding another copy of the text.
How can I draw text without really drawing the text itself? Changing the fill color to clearColor doesn't work. I've seen people use clipping masks for this, but AFAICT that will only work for simple shapes, not text.
Alternatively, is there an easier way to draw two shadows on the same text?
Two options, depending on the exact effect you want:
If you want the first, "upper" shadow to also contribute to the second, "lower" shadow underneath it, use a transparency layer.
Set your CGContext's shadow for the "lower" shadow
Create a transparency layer using CGContextBeginTransparencyLayer
Set the context's shadow for the "upper" shadow
Draw your text
End the transparency layer using CGContextEndTransparencyLayer
(Note that transparency layers can be quite expensive. It's best to call CGContextBeginTransparencyLayerWithRect and pass in as small a rect as you can.)
If you want the shadows to be independent -- the only thing that contributes to each shadow is the text -- you'll need to use a trick.
Set up the shadow with an additional large offset, big enough so that you can draw the text outside of the bounds of your context and have the shadow land in the correct place. That way you'll see only the shadow, but not the text.
Figure out what offset is "big enough". It will probably depend on the size of the context you're drawing into (based on your view), and maybe the bounds of the text.
Or, just fudge it: pick an absurdly large value like 5000 pt.
Set up your shadow. Add the big offset to its normal y offset.
Draw the text, offset vertically by the big offset.
Repeat 1-3 for each "lower" shadow, from back to front. Afterwards, draw the text and the "uppermost" shadow last, without the offset.
I have a NSBezierPath, in the shape of a menubar panel.
I'd like to make a header now.
Like this one for example.
But only like 30 pixels from the top.
I can't figure out how I should only get the top part of the NSBezierPath.
This is my first question.
How can I cut off a piece of the NSBezierPath, or how can I make a Union of the NSBezierPath.
Then I want to add a gradient like in the example.
The gradient is clear, but how can I add the glow at the top of it?
I have added a shadow in another app back then, but it seemed a little dirty.
So how can I make a shadow at the top of the NSBezierPath, like in the provided example.
Thanks!
I ended up using PaintCode, which did a pretty good job for me.
This is the result:
To get the 'light' edge at the top of the element you can just draw (i.e. :fill) the NSBezierPath with a vertical offset of e.g. -1 points with a brighter color. Then draw the shape (at y=+1 points) on top of that.
Not sure what you mean by making the header and cutting of bits..
I wanna draw a UIButton filled with a red tint color or some color else presented by rgb and only the upper edges are rounded.
some people answer me to get an image to do that but every time i want to change it i have to bring new image and replace it, I wanna ask can i do it from code without get an image.
There is no direct way. Only way to achieve this to create a segment control and keep only a single segment in that.
See this post for detailed implementation,
Update:
If you want to round only two corners check Round two corners in UIView or Just two rounded corners? as mentioned in rdurand's comment. Since segment control is a subview of UIView, this should work.
You can draw the rounded corners using NSBezierPath s bezierPathWithRoundedRect:xRadius:yRadius: method. And then draw over it with another bezier path. Or you could just define a custom bezier path using moveToPoint: lineToPoint: and curveToPoint:controlPoint1:controlPoint2:
Take a look at this:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html
I have a UIView that allows the user to draw a line (myLine) on the screen. This UIView is directly above another UIView that has several shapes drawn with CGPaths. When the user taps on one of these shapes I need to erase any portion of myLine that is above one of these other shapes as if I was erasing the pixels with an eraser.
What would be the best way to approach this?
I need the light blue part of the line to be erased leaving the dark blue portion
1) (current approach partially works) I'm able to use the path shape from the bottom view as a mask in the top view but it is only masking the UIView. If I later need to change the mask location the vector strokes are still there. (I know this is because all off my lines are being redrawn in the drawrect of the view)
2) After I draw each line should I somehow cache the drawing as an image and THEN
slice out the parts inside the triangle?
3)Is there a better approach to this?
This link provided the answer:
Building a Simple Drawing App
I cache the drawing to a bitmap context and then clip out
the unneeded parts of the bitmap.
I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop)
As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!
You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.
The text is first used to create a clipping path, and the gradient is drawn within that path.
As far as the internal shadow, you might be able to draw this after the gradient is drawn by using CGContextSetShadowWithColor() with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.
Draw the text with a normal font to create a black and white bitmap of the text.
Draw another image that is is the same size and completely filled with the gray-to-white gradient you have above.
Create a completely white image with the same size as your other images.
Draw your back and white text image (1) onto the white image (3) with NSCompositeDestinationOut.
This gives you a white image with your text cut out.
Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.