UIImage position on screen/window/superview - ios

I want to add a UIButton to the end of NSAttributedString. I was unable to do that as NSAttachment only takes a UIImage.
So, I've added a UIImage to NSAttributedString as attachment and saved its reference. Now i want to obtain the position of this UIImage on UIScreen, UIWindow or Superview to put a UIButton at the position of image. Is it possible?

Related

Get uiview section under uiimageview?

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.

I can change tint colour on UIButton but not UIImage

I am playing around with tint colours on a UIImage and a UIButton.
On the UIButton (when the button type is set to System), I am able to set the tint colour of the UIButton in Xcode by going to Attributes Inspector -> View -> Tint
On UIImageView, I have set the same image, but when I go to the Attributes Inspector -> View -> Tint, the colour of the image does not change.
Why is the behaviour like this ? and how do I fix it ?
I am using iOS 7 and Xcode 5.1.1
Your image's rendering mode needs to be set to template and not original. To do this, you can call the -[UIImage imageWithRenderingMode:] method on your image and pass in UIImageRenderingModeAlwaysTemplate, then set your image view's image to the resulting image:
yourImageView.image = [yourImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
Or, in Swift:
yourImageView.image = yourImage.imageWithRenderingMode(.AlwaysTemplate)

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.

iOS - how do I only update my UIImage on the UIView

I've got an UIImage on a UIView. Instead of redrawing the entire UIView, I just want to redraw that specific UIImage. How do I do that?
UIImage on a UIView is not possible. I Think you mean a UIImageView on a UIView.
You can send to the UIImageView...
[yourImageView setNeedsDisplay];

Resources