UIImage sliding indicator size - ios

I have 2 UIImage's one on top of another and the top one slides and reveals the coloured one. The issue is that I want the indicator (purple line, which is a view) to indicate in the left side only by the end of the image (image`s background is clear).
What I want is to resize that purple line so it wold be visible in the left side and on the image but not on the right side, as it is now.
Any ideas of what I can try ? I have no idea where to start, thank you!
What I did so far:
what I want:

It is possible to implement programmatically using CGImageCreateWithMask, but it is very hard. Also such solution will be not very fast, if you want to do it in real time.
I offer next solution: create 3-d image, as shown below. That picture must be a white mask, which will limit your line. Place that picture above pic 1 and 2. Pink line should also be placed below that picture.
Sorry, if I wrote something unclear.

Thanks kelin, the idea that you gave me was interesting, but I did not had time for that, so I found another way of doing this. I used a third image for the mask witch is an image with the lady`s shape cut off and a white background but only in the right side of the picture (the left half side image and lady shape is transparent), and the line crosses on top of the pictures shown previously and under the image I added with mask...
Simple and efficient, and it uses way less memory for a real time displaying with an animation .

Related

Show part of image in a circular arc

I have an image which is like a progress bar in circle. I need to show only a part of the progress bar based on the progress percentage. What I am trying to do is to put the image inside an imageview and show only a part of the image (arc section of the entire circle) based on the progress.
I have tried using UIBezierpath to create an arc shaped view and setting my progress bar image as the background image. But the image will try to fit inside the arc shaped view and looks bad.
Is there a better way to achieve the same?
Edit: Here is a sample image of what I am trying to achieve
But instead of the blue background, I need an image. So, only part of the image will be visible depending on the progress. (When its 100%, the entire image is visible)
I have spend almost half a day on this one. Any help would be appreciated.

Camera Overlay Image Is squished on iPad

So it seems that because of the menu bar on the right hand side of the gui, the overlay I'm adding is being squished. The image I'm getting from the artist is a square, but once the overlay is applied inside the camera it is no longer square. What do I have to do to get the image to be applied for the whole screen, or what must I do to get the square to appear as a square in my app? Any ideas about how to get over this problem would be appreciated. Thanks.
Sincerely,
Sean
I thought this was an Xcode issue, but it turns out I was subtracting 100 from the width because of a problem I was previously solving. Sorry for wasting your time on this one- the problem was in my code.

Trim transparency of an UIImage

I was wondering what would be the best way to trim the "canvas" of an UIImage (pretty much like any image editor allows out there)
Now, the previous example is not a single UIImage. It's actually 2 UIViews. So clipping the superview against the blue box would do the trick, but I guess I am looking into the best possible way to do this. Given that there could be several blue boxes in the "canvas".
Is there a faster way than going through every pixel?
Thanks!
Thinking about it algorithmically, I would say no. You need to find the pixel that extends furthest to the left, right, top and bottom. Unless you look at every pixel from each direction you could miss non-transparent pixels.
You could speed things up if you figure out how to map your image into memory and then index into memory directly rather than using a high level function that fetches pixels. I would suggest searching from the top down (which would be sequential memory accesses) until you find a non-clear pixel. Then search from the end of the image backwards, which would give you the bottom-most pixel.
You would then want to limit your search from each side to only look starting at the first non-transparent pixel from the top and ending at the last non-transparent pixel on the bottom.
For anything other than a very large image this should take a fraction of a second.
Ok, I was being dumb. The union of the subviews is all I really needed, so its just a simple loop over the subviews and doing a CGRect union against their frames.

masking a background colour over the transparent region of a UIImage in objective C

Im a little bit lost on how to go about this, im really looking for the theory behind it im not 100% sure if the title is correct or not.
Im currently working on a iOS app and im a little stuck with the progress indicator thats been designed ive attached a image of it below
as you can see when the user progresses through the stages of the challenge the background of this image fills up with white so if they are in stage 1 of a 5 stage challenge its filled 20% stage 2 40% etc.
the issue I have is im not 100% sure how to go about this, if I was doing this in HTML i would create the image with the green background and leave the area for the rabbit and shape transparent and then create a div behind it that would change its height.
should I be applying the same principle to iOS development or should I be building it in a more programatic and efficient way.
thanks all for your help
The solution you are talking about sounds fine. Many programmatic solutions would involve masking and would probably be less performant (masking is actually quite expensive), other programatic solutions involve stroking different vector paths but that would get complicated if you want to cut them all of a the same line.
So, translating your idea into views. Create a container UIView with a light green background, and add to it a white UIView and an UIImageView (in that order to get the image on top). The image view would have the green image with transparency set as its image. The white view would start of being positioned below the light green view (have a frame with a higher y value) and as the stages progress you simply shift the white view upward by modifying it's center or frame properties. (note that y increases downwards).
This may be a childish way
Make an UIImageView and add that in your view where you place your rabbit view.
Make the width and x axis value as same of your rabbit view and change the height and y-axis value as the stages completes.
Add the rabbit view above your imageview.
In this way you can have not only color of your progress you can even assign a image in future to show the progress of the different changes.
-(void)completedStage:(int)stage
{
CGRect frame=rabbitimage.frame;
bgimageview.frame= CGRectMake(rect.orgin.x,rect.frame.orgin.y+rect.frame.size.height-stage*0.2,rect.frame.size.width,rect.frame.size.height-0*2)
}
Hope this helps !!!

Create background image with margin on EditBox

I'm trying to create a EditText box, like below which has a image on the left hand side and editable text region on the right hand side, but I don't seem to have the slightest clue how to do this in android :| I can find various solutions for putting an image in the background (so the text can overwrite it) and also how to make the rounded corners, but I cannot find a way to put the image on the left and the text on the right.
Any pointers would be very much appreciated!
Make a background graphic including the image and the border with the rounded corners. Make an EditText with this graphic as background and adjust the EditText with the android:paddingLeft/Top/Right/Bottom properties.
After much researching the best way that I could find was to make use of drawable left right top and bottom, along with a drawable padding. This would mean that the button scales easily. #CodeDownZero 's suggestion is also valid. I think its a matter of personal preference in this case.

Resources