2

Hello: Currently in my project, I'm using OBShapedButton to process touches on a lot of objects that overlap (it's a map with each territory its own separate object). Basically, this library prevents a touch from being processed on a transparent point on the given view.

I'm attempting to add a border effect to just the edges of the opaque part of the UIImage (and adding a semi-transparent overlay above that). Something to the effect of this:

Example

Which can be simplified to this (example of one image): Simplified example

I am currently using MGImageUtilities to color in the opaque parts of territories using this line:

[territory setImage:[[territory image] imageTintedWithColor:tint]];

The problem is that I'm not sure how to just color the borders (which can be any shape). I've looked at this link already, but haven't been able to come up with anything.

Thanks in advance for the help!

rebello95
  • 8,486
  • 5
  • 44
  • 65

2 Answers2

2

Terribly hacky, but use MGImageUtilities' UIImage+ProportionalFill with scale resizing to create a slightly larger image, UIImage+Tint to red, and stack below.

Thompson
  • 1,098
  • 11
  • 25
  • Very interesting idea... Do you know if it's possible to combine the two images into one? So, for example, to overlay the original image on top of the edited one? – rebello95 Aug 26 '14 at 05:35
  • Add the new image as a subview to the same container that holds the OBShapeButton, using `insertSubview:belowSubview:` to get it positioned correctly. I am sure there is also a more resource-intensive and complicated way to combine both images in a `CGImageContext'. – Thompson Aug 26 '14 at 07:03
  • Good call. Looks like this could work: [Reference](http://stackoverflow.com/questions/9208951/ios-merging-two-images-of-different-size). Thanks for your answer. I'll accept it if nobody comes up with anything better. – rebello95 Aug 26 '14 at 07:07
0

The library you are using doesn't actually specify a shape layer. It uses alpha values from the PNGs that you give it.

Could you use a different 'highlighted' or 'selected' PNG that adds the border effect you are looking for?

Otherwise, it you will have to generate a UIBezierPath from your PNG image, which sounds like a very computationally intensive operation. At that point, I might question whether this library meets your needs.

Jeff Holliday
  • 760
  • 6
  • 7
  • You are correct about the library's use of `alpha`. I wouldn't be able to use a highlighted/selected PNG file because that would require duplicating a lot of files unnecessarily (I'd need one of each color for each territory). You're right, it may not be worth it at this point... I'm looking into just putting a filter over the image and forgetting about the borders. Thanks for your answer. – rebello95 Aug 25 '14 at 23:33