Make view stand out from the surroundings. Border layer with inverse color? - ios

I have a view (a Button in this case) and the content behind/below it can move around (a ScrollView). The button is just plain white with black text and not bordered with anything. When the content behind the View is white it does not really stand out as I would like it to do. (I can fix this with a black border sure... but...)
I have this idea of having a border around the button that is the opposite color of the view (pixel) behind it. So the border would always contrast with the background and constantly change with the content behind it.
I have googled a bit and looked into visual effects layers and some more complicated (over the top of my head) graphics stuff I don't remember the terminology for.
If you have an idea of how to approach this please tell me. I just really want to see what it would look like.
and have a wonderful day!

I don't think you can create a border that uses colors based on the color of the pixel from the layer behind the current layer using CALayer and borders.
What I would suggest doing is to add a second CALayer to your view's CALayer, inset by -1 in both dimensions (made 1 pixel bigger.) Let's call that the surroundLayer. Then make the surroundLayer's borderColor be white and the view's layer.borderColor be black (or visa-versa.) You can make the surroundLayer's borderColor be 50% opaque so it just lightens/darkens the pixels under it without completely obscuring them, and that is enough to increase the contrast and make your view's border show up regardless of the contents under it.
I've used this technique before and it works well.
Edit:
Check out the project https://github.com/DuncanMC/MaskableImageView.git. The project demonstrates using an image as a mask layer to hide/reveal the contents of a view.
The class MaskableView in that project draws a circular "cursor" that shows where it is revealing/masking the contents of its subview (an image and a label, in the example app.) The cursor is yellow in the middle, with a partly transparent black outer circle around it. This gives good contrast regardless of the colors in the part of the image it is being drawn over.
The MaskableView class has properties that let the caller set the colors use for the "cursor" circle.
Below I posted a short animation of what the eraser tool with a yellow inner circle and an outer, 1/2 transparent black circle looks like.
Without the outer dark circle the yellow inner circle tends to get lost in brighter parts of an image. With the combination of a bright colored inner circle and a partly transparent, dark outer circle, it's easy to see on ANY background:

Related

XNA Alpha Blending With Primitives and Sprites

I've been using XNA for awhile now and I really enjoy using its interface. Right now we're trying to make a "fog of war" system. We're making an RTS and we're basically trying to obscure the map. Units on the map have influence, and show what's happening. They reveal a specific area on the map. Previously we used a tile based interface but we weren't happy with the appearance. Instead, we decided to draw a black mask on the screen, then reveal a transparent circle with DrawUserPrimitives. Here's the problem: When we draw a black mask on the screen, followed by the transparent circle, the screen is entirely black. Reversing the order doesn't change anything either. We've also tried every SpriteBatch BlendState we can find.
OUR CURRENT METHOD:
Right now, we're drawing a full black texture onto the screen, then drawing a transparent circle. The result is an entirely black screen.
OUR DESIRED OUTCOME:
Drawing the circle will reveal a section of the screen, but keep the rest obscured. We'd be able to draw multiple circles, all with their own radius, that would could be near each other without causing problems.
Basically, we're trying to draw a black mask, but reveal portions of the screen. We can't just make a circle texture and make the edges transparent, because we're trying to make the center of the circle transparent. We can't make the center transparent, because then when two such textures were near each other, their borders would show up. How would I go about making the mask, then revealing sections of it?
Regards
Ares
You could render the graphics normally to one render target, then paint the visible area in white on a black background in another render target, then render the second into the first with the Min BlendFunction.
Alternately, using only one render target, draw the graphics normally, then clear the alpha channel (by painting a rectangle over the whole screen with ColorWriteChannels = Alpha and alpha blend factors both 0), then draw the visible area with ColorWriteChannels = Alpha only.

Placing an image in a specific region of another image

Here is an oval, and a box
The goal is to place the oval inside the green box.
If you imagine the green box on the bottom to be your bounds, the top image can be placed anywhere inside the green box. The oval cannot flow outside of the green box.
Input is just the two images and I'm told to "put the red oval in the green box." If it is not possible (eg: the oval is too big), nothing happens.
It is trivial to do it by hand in a image editor: just drag the top image over the green box and make sure it doesn't flow out the sides.
How should this problem be approached?
There are a variety of ways of doing this and choosing one depends on problem constraints. In the simplest case, if you know the exact colours of the red, blue, and green, and know that none of the shapes are rotated the solution is simple. First binarize the image so that only one object is separated (oval or rectangle) then find the highest,lowest,leftmost,and rightmost point for that object. Repeat for the other object. That information will tell you if the ellipse can fit in the rectangle.
If those constraints are too rigid, then you will probably want to use blob detection. Perhaps cvblob or cvblobslib. They can handle the much more general case of varying colours and orientations.

Making a UIImage in UITableViewCell look recessed

This is sort of a photoshop question, I suppose, but does anybody know how to make a nice looking heart that's recessed? Sort of like this one, except recessed:
There are a few layer styles which can compliment each other to give you that recessed look.
A light drop shadow beneath the sprite (1px white shadow directly below usually does the trick, but you can experiment with its softness/size)
A gradient which is darker at the top and lighter near the bottom
A dark inner shadow which is at the top of the sprite. (1px black, for example)
If you're doing this in Photoshop, make sure to have the light angle set to 90ยบ
A basic letterpress effect can be achieved by having a white (or light coloured) drop shadow 1 point below the image. This is what is used in iOS for the status bar images and text, for example.
You may also want an inner shadow inside the top edge, and possibly a subtle gradient (lighterdarker at the top - note I have changed my mind on the gradient, but not updated the image!) instead of a solid background colour.
Here's a 5 minute bodge job done in Pixelmator. The inner shadow at the top is particularly amateurish, but I prefer drawing things like this in code!

Truly transparent gradient possible in Fireworks CS5?

Does anyone know if it's possible to have a gradient created using Fireworks to be really transparent at the bottom?
I'm trying to create a gradient which is truly transparent at the bottom, so it can be placed on top of another image. As far as I'm aware, even though the opacity of the bottom is 0, I still have to select a color for the bottom. This makes the top color blend into it (like below it's blending into white). So whenever the image is placed over a dark image the bottom is transparent but still white.
Hope that makes sense. Thanks for the help.
I usually achieve this effect by setting both color endpoints of the gradient to the same color, then adjusting the opacity endpoint to 0% (or whatever you want).
Here's the result: This is #666/100% to #666/0% on the left, #666/100% to white/0% on the right.
I was having the same problem you should try working with auto vector masks
Command>Creative>Auto Vector Mask
Great little tutorial here
http://www.communitymx.com/content/article.cfm?cid=b5f64
How are you defining "really transparent"?
You must choose a linear gradient, then a colour at each end of the gradient, and then make one end opacity 0%. It doesn't matter if it is a colour or not, you make it invisible anyway.
If you are comparing it to something like Photoshop or Illustrator, yes it's annoying that Adobe cannot be consistent with how each application handles opacity, but in Fireworks, it's still the same effect, just a different method of doing it.

drawRect: How do I do an "inverted clip"

I am creating an iOS user interface to allow a user to pick a rectangle within an existing image, dragging the corners of that rectangle to the desired size. I now have four custom UIButtons (30% alpha) and a custom view (also with 30% alpha) that draws the dashed lines between the four corner buttons.
To "improve" the interface, I would like my drawRect code to make the cropped portion of the image appear "normal" while everything outside the cropped region is washed out (filled with white color, which will give me the correct effect since the UIView is set to 30% alpha).
The obvious algorithm would be:
Fill the entire image with [UIColor whiteColor] fill
Draw the four dashed lines with a [UIColor clearColor] fill
When I do this, the clear fill isn't showing up. I believe this is because the "fill" of the clear color in step #2 isn't being seen because the pixels were already set to white in step #1. Perhaps there's a blend mode that will allow me to see the transparency of the second rectangle? I'm not sure about the various blend modes.
My second attempt, which works, does the following:
Draw the four dashed lines with [UIColor clearColor] fill
Draw four additional rectangles with [UIColor whiteColor] fill, each representing the portions to the left, right, above, and below the cropped region.
As I mention, this method works, but seems to me there should be a simpler way instead of me having to calculate these four additional rectangles each and every time.
There is a similar question on SO Create layer mask with custom-shaped hole that uses CALayer and masks, but this seems to be overkill for what I need.
Does anybody have any suggestions on how to improve this?
You can set the blend mode to kCGBlendModeCopy and use clearColor to reset a pixel's alpha to zero. You can presumably also use kCGBlendModeClear but I haven't tested that.
You can also set the clipping path to just contain the pixels you want cleared and call CGContextClearRect(gc, CGRectInfinite).
If you want to use a clipping mask with a hole in it, you can do so without using a CALayer, and you can build it a little more simply than in the answer you linked, by using the even-odd rule and CGRectInfinite:
CGContextSaveGState(GC); {
CGContextBeginPath(gc);
CGContextAddRect(gc, myRect); // or whatever simple path you want here
CGContextAddRect(gc, CGRectInfinite);
CGContextEOClip(gc);
// drawing code here is clipped to the exterior of myRect
} CGContextRestoreGState(gc);

Resources