EzDevInfo.com

uiimageview interview questions

Top uiimageview frequently asked interview questions

UIImageView aspect fit and center

I have an image view, declared programmatically, and I am setting its image, also programmatically.

However, I find myself unable to set the image to both fit the aspect and align centre to the image view.

In other words, I want the image to:

  • Scale down to fit the aspect, if the image is large.
  • Centre but not scale up, if the image is small.

How do I get that?


Source: (StackOverflow)

How to write text on image in objective-c iPhone?

I want to make an image like this through programming

I have the upper image and text with me. Should I write text on image or any other suggestion for it.

I want to make it a complete png image(image + label) and set it as the background of the button.

Please provide any sample code or any suggestion for it.


Source: (StackOverflow)

Advertisements

UITableViewCell with image on the right?

Is there a way to set the UITableViewCell.image to display on the right hand side of the cell instead of the left? Or will I need to add a separate UIImageView on the right side of the cell layout?


Source: (StackOverflow)

IOS: load an image from url

I need to load an image from a url and set it inside an UIImageView; the problem is that I don't know the exact size of the image, then how can I show the image correctly?


Source: (StackOverflow)

How to make a circular UIView

I want to make a UIView or UIImageView that is a circle. Or a circle that i can change the size of using a slider, and the color of with a pickerview.


Source: (StackOverflow)

How to display a base64 image within a UIImageView?

I got this Base64 gif image:

R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7

Now I want to display this Base64 String within my IPhone App.

I could get this working by using the WebView:

aUIWebView.scalesPageToFit = NO;
aUIWebView.opaque = NO;
aUIWebView.backgroundColor = [UIColor clearColor]; 
[aUIWebView loadHTMLString:
  @"<html><body style=""background-color: transparent""><img src=""data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7"" /></body></html>"
 baseURL:nil];

Is it possible to do the same thing by using the UIImageView?


Source: (StackOverflow)

How to compare UIColors?

I'd like to check the color set for a background on a UIImageView. I've tried:

if(myimage.backgroundColor == [UIColor greenColor]){
...}
else{
...}

but that doesn't work, even when I know the color is green, it always falls into the else part.

Also, is there a way to output the current color in the debug console.

p [myimage backgroundColor]

and

po [myimage backgroundColor]

don't work.


Source: (StackOverflow)

Fade/dissolve when changing UIImageView's image

Rather than creating two UIImageViews, it seems logical to simply change the image of one view. If I do that, is there anyway of having a fade/cross dissolve between the two images rather than an instant switch?


Source: (StackOverflow)

Text views and image view disappearing from view controller in Xcode 6.1 storyboard

I updated to Xcode 6.1 to fix an error I was having with the Interface Builder Cocoa Touch Tool spiking to 99% CPU usage when I used the storyboard, which would freeze Xcode. Now that that error is fixed, I have a possibly even more frustrating error.

When I use the storyboard, while I'm working on a UIViewController, my UITextView, my custom UITextViews (which are subclasses of UITextView, but for all intents and purposes in the storyboard, they're UITextViews), and my UIImageView suddenly disappear!

Here's how the default main view inside my view controller looks right now:

Main View

  • View
    • Activity indicator
  • Scroll view
    • Label
    • Text view (x=0, y=-65, width=0, height=0) ERROR!
    • Label
    • Custom text view (x=0, y=-65, width=0, height=0) ERROR!
    • Label
    • Custom text view (x=0, y=-65, width=0, height=0) ERROR!
    • Label
    • Custom text view (x=0, y=-65, width=0, height=0) ERROR!
    • Label
    • Label
    • Custom text view
    • View
      • View
        • Label
        • Button
      • Image view (x=0, y=0, width=0, height=0) ERROR!
    • ViewX
      • Label
      • Custom text view (x=0, y=-526, width=0, height=0) ERROR!
      • Width and height Constraints for this view.
    • Button
    • Width and height constraints for the scroll view
    • Center x and y constraints for ViewX within the scroll view.
  • Center x and y constraints for the scroll view within the main view.

It all started when I adjusted the size of the view controller using "freeform" in order to see views that were off the view controller screen. Once I used cmd-Z to change the view controller back to "fixed" (to the normal size), the missing elements appeared again and everything seemed fine. However, later on, I was editing the view controller and suddenly...bam! They're gone. And when I reset all of them to where they were supposed to be, it just happened again (resulting in the above described x, y, width, height values).

:-(

Does anyone know what could be wrong? I never had this error in Xcode 5.

EDIT:
I was able to use cmd-Z to get the view controller back to normal. Then I restarted my mac and reopened Xcode. Now, I've noticed that the error occurs whenever I resize anything in the storyboard by dragging with the cursor (it doesn't happen if I resize something using the width and height properties on the right panel in Xcode). It happens on other view controllers as well. Even in a view controller that has only a UILabel and a UIImageView in the default main view, when I click and drag the edge of the label to resize it, the image view disappears with values of x=0, y=-64, height=0, width=0.

CONCISE SUMMARY:
In the Xcode 6.1 storyboard, every time I resize any elements in a UIViewController, all UITextViews and UIImageViews collapse and get shoved -64 pixels above the upper left corner of the view controller.

UPDATE
It appears that Xcode 6.1.1 has fixed the bug.


Source: (StackOverflow)

What happens to SDWebImage Cached Images in my app when the image file on the server changes?

I am using the SDWebImage library to cache web images in my app:

https://github.com/rs/SDWebImage/blob/master/README.md

Current Usage:

[imageView setImageWithURL:[NSURL URLWithString:profilePictureUrl] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

My question is what happens once the image has been cached and then a couple of days later that image file on the server has been updated with a new image?

At the moment my application is still displaying the cached image.

I can't see in any of the documentation on setting a cache timeout or something that recognises that the file size has changed.

If anyone has experience using this particular library then any help would be greatly appreciated.

Thanks in advance.


Source: (StackOverflow)

BSXPCMessage received error for message: Connection interrupted

UPDATE: Reference #19285042 and submit bug reports to apple

Very weird error and not finding anything online. Its saying "BSXPCMessage received error for message: Connection interrupted"

I'm just doing some basic filter applications. The error message ONLY occurs if I reassign the UIImageView.image to another UIImage. If I comment out just that line I will not get the error. So if you can think of any reason why this message appears when I assign a filtered image to a UIImageView that would be incredibly helpful.

If you can suggest any cause for this error I would appreciate it.

#import "FilterTestsViewController.h"

@interface FilterTestsViewController ()

@end

@implementation FilterTestsViewController

UIImage* _originalImage;
UIImage* _filterImage;
UIImageView* _uiImageView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initialize];
    //flip image by 180*

}

-(void)initialize
{
    _originalImage = [UIImage imageNamed:@"ja.jpg"]; //creates image from file, this will result in a nil CIImage but a valid CGImage;
    [self createFilterImage];
    _uiImageView = [[UIImageView alloc] initWithImage:_filterImage]; //creates a UIImageView with the UIImage
    [self.view addSubview:_uiImageView]; //adds the UIImageView to view;
}

-(void)createFilterImage
{
    NSString* filterName = @"CIFalseColor";
    CIImage* ciImage = [CIImage imageWithCGImage:_originalImage.CGImage];
    CIFilter* filter = [CIFilter filterWithName:filterName keysAndValues:kCIInputImageKey,ciImage, nil];
    _filterImage = [UIImage imageWithCIImage:[filter outputImage]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

Source: (StackOverflow)

Add animated Gif image in Iphone UIImageView

I need to load an animated Gif image from a URL in UIImageview.

When I used the normal code, the image didn't load.

Is there any other way to load animated Gif images?

Please help me.

Thanks.


Source: (StackOverflow)

Apple Interface Builder: adding subview to UIImageView

I created UIImageView with the help of Interface Bulder. Now I want to place label inside it (as its subview). In code I can type something like: [myUIImageView addSubview:myUILabel]; But can I do it with the help of IB? I found the solution for UIView, but can't find something similar for UIImageView.


Source: (StackOverflow)

iPhone: Camera Preview Overlay

How do I add an overlay (UIImageView) to the camera preview and handle touches on this?

My previous attempts to do this (e.g. use UIImagePickerController and add the image as a subview) have failed.


Source: (StackOverflow)