Get uiview section under uiimageview? - ios

I have an UIView as background, and a UIImageView above it.
What I want to do is fill the UIImageView with the UIView section that is in the back (without the white border)
I tried cropping a snapshot of the background but it doesnt look good. there is always a difference.

Make the background UIView a subview of the UIImageView and then set the property of the UIImageView yourImageView.clipsToBounds = YES

Use CALayer mask. The mask will be the smaller image view, and will be assigned to the background view's mask property.

Related

how to make visible other components in transparent UIVIEW in swift 5

I have used a UIVIEW . I want to make transparent the UIVIEW. But when I want to chage alpha 0.0 from storyboard for make UIVIEW transparent, textfield, label and other component also transparent. I want to make transparent UIVIEW, not other component of the view. Here is the image
Please help me to make visible other components in UIVIEW transparent
Set your UIView's backgroundColor to UIColor.clear.
Instead of changing the alpha of the UIView, you can make the background color of your UIView as white with alpha component 0.5 or something
myView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
If you want it to be completely transparent, you can set backgroundColor to clear from storyboard as well as code.
myView.backgroundColor = .clear
You just need to change the transparency not of the UIView itself, but of its
background color.
For example:
I set the color of the UIView transparent, while the UILabel remained its settings.
In order to create a semi transparent color, you can use the following code:
yourView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
Hope this will help you!
Go to Main.Storyboard and select the view you want to make transparent.
From the Attribute Inspector select background color as custom.
Then set your desired color and decrease the percentage of Opacity of the color.

uiscrollview zoom to overlay rect

I want to tap to zoom a UIImageView and put it inside a overlay.
Just like this picture.I want to put the cyan color rect to the blue one.How can I do this?
You can use multiple CALayers. CALayer can be overlaid easily, as you can stack sublayers

Setting UIScrollView Background Image

I have a scrollview that takes up the full display size on a view. I want to set the background to a static image. I don't want to tile it, so I don't think I can use backgroundColor. Also, I don't really want it behind the scroll view (setting the scrollview to transparent) because I want bg to scroll with the scroll view.
Any help would be great. Thanks!
Try setting a tillable image as your background color.
scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tileableImage.png"]];
Just add a UIImageView that is the same size as the scroll view's content size
When we set image to scrollview as a background then that is scrolled with scrollview. So instead of setting image to background , set image to view
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "bg.jpg")!)

Draw random image on a bubble image background like iMessage

This is a chat app, the bubble is the background image, for text, i can just stretch the bubble image with "resizableImageWithCapInsets", and draw the text on the bubble.
But problem is when it is a random image, how can i draw the image on the bubble the way it is in the attached picture? both ios message and imessage on mac show the image in this way.
http://i.stack.imgur.com/sgJhv.png
If your bubble is represented by a UIImageView (which is a subclass of UIView), you can add another UIImageView as a subview of your bubble. You would make the frame of this subview equal to the frame of your bubble, and then set the bubble's clipsToBounds property to YES, so the subview is constrained to the bubble.
You would then set the contentMode of the subview to UIViewContentModeAspectFill, which will strech the image to the size of your bubble. Something like this:
//After resizing the bubble to the size you want, to this:
bubbleView.clipsToBounds = YES;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:bubbleView.frame];
imageView.image = theImage;
imageView.contentMode = UIViewContentModeAspectFill;
[bubbleView addSubview:imageView];'
[imageView release];
Take a look at BubbleThingie sample app. It does the image masking and gloss effect like in your example image.

Overlaying UIView with an background image

Is it possible to overlay UIView with an image without using UIImageView from the Interface Builder?
If not, how would you accomplish the same in code?
From the UIView documentation:
Image-based backgrounds - For views that display relatively static content, consider using a UIImageView object with gesture recognizers instead of subclassing and drawing the image yourself. Alternatively, you can also use a generic UIView object and assign your image as the content of the view’s CALayer object.
Using the second option, to set someView to have a background of yourImage.png:
someView.layer.contents = (id)[[UIImage imageNamed:#"yourImage.png"] CGImage];
if by Overlying a UIView you mean painting its background with an image, it can be done like this:
someView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"yourImage.png"]];
You could also add a new UIImageView that covers your UIView
by code, Init your UIImageView with the same frame Rect as your UIView and add it as a subview.

Resources