Mask an UITextView / UIView - iphone

Is it generally possible with an UITextView to have a mask which I can animate at runtime? Imagine a flash light effect: You have a circle mask and then move this circle around -- and only whatever is in the circle is shown of the UITextView.
Sorry to be so general, but I was only wondering if this is generally possible with an UITextView and where I would need to start to achieve such an effect. I found this: Mask UIView and this Mask text inside UITextView but neither is really about animating a mask at runtime.
Thanks!

Yes this is completely possible and easy.
It is very likely you *do not need the difficult concept of masks, as explained in the links you mention.
All you have to do is make another UIView (just do it in IB), and then move that new UIView around as you see fit.
It's just that easy. Hope it helps.

Related

Make bottom part of UITextField(UIScrollView) transparent

Here's a good example that sums it up:
This is a UITextField that contains long text, so the user is able to scroll down to view the rest of the text.
How can I make the bottom rows appear "transparent"?
UITextField only allows setting global text properties (like color, font size, etc).
The trick is to create a CALayer containing a gradient and use it as mask layer of your UIView's layer (alpha values of the mask layer will be used.) see this answer: UIView border with fade or blur effect
This will help you.Not sure but some functionality like you want.
Hope this helps you.
All the best !!!

Hide / reveal UIImage based on finger path?

I hope that makes sense. I'll try to explain it.
I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.
I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.
If I understand your question,
I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.
you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.
You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:
imageView.layer.mask = maskLayer;
Hope that gets you started.
For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide
So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then
1) Store your strokes in an array, and stroke all of them over top of the image.
2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.
I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);

how to create a pointy UIView

I just saw local mind's app and they have a horizontal UIScrollView that has a selection with a pointy tip. How can I create such thing? I saw this often times in many apps where you don't just have a square frame, but you have a pointy edge to it, is this just a UIImage overlayed on top?
Other example would be this
If you disable clipsToBounds in the horizontal UIView (which is default), its subviews are allowed to stick out and draw past the edge of the frame.
Thus, yes, a UIImageView was probably how it was accomplished.
This is most likely achieved using an image. As simple as that.

Drawing in a UITextView

I'm trying to make a UITextView look like a piece of paper with the red lines, margins, etc.
I haven't found anything that would allow me to use graphics in a UITextView and I can't use a UITextField because I need to allow multiple lines...
I've tried drawing in a normal UIView and then trying to blend that with the UITextView but that apparently wasn't the right approach.
Any help would be great. Thanks!
Do you just need a background image? This thread may help:
UITextView background image

Most effective way of drawing 4 lines in an iPhone app?

basic question, but I'm unsure. Not looking for code as an answer.
I want to draw 4 short lines 1px lines on a view. What is the best way to approach this task? Options:-
Load an image of the line, then create 4 UIImageViews with it.
Create my own subclass of a UIView that draws a line in the draw rect method.
Draw elsewhere on another view, another UIImageView that has an UIImage inside it (is this possible?)
Another way?
Thanks
Ross
Simplest way is to create a UIView subclass and perform your drawing in drawRect:. See the CoreGraphics guide for details on how to draw a line.
Quick and dirty way to achieve this is to just create a UIView and set it's height (or width, depending on its orientation) to 1px, and then set a background colour and slap it onto your view as a subview.