Content mode issue in UIImageView when its set to ASpectFill - ios

I need to load an image in a cell and i get a white border along my image.I'm calling the image from the link and it looks like this.
but my image looks like
i'm getting a white border in my image left and right side.Here is my code for image
UIImageView *item=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 115, 130)];
NSString *imgstring=[NSString stringWithFormat: #"%#",[[mutarray objectAtIndex:indexPath.row ] valueForKey:#"imgurl"]];
NSURL *imgurl=[NSURL URLWithString:imgstring];
UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:imgurl]];
[item setBackgroundColor:[UIColor clearColor]];
item.contentMode=UIViewContentModeScaleToFill;
[item setImage:image];
[cell.contentView addSubview:item];
Guidance please...

Those white side borders are in the image you posted in your question....that's why they appear in iOS as well. Open that picture in a photo editor and you will see.

You can solve it by editing webimage becaust it has white background in that u can add the following code to differentiate the image by giving
item.backgroundcolor=[UIColor blackcolor];
Hope it helps..

Related

How to design UIButton Like UITabBarItem in iOS?

I have to place 6 buttons in the bottom of particular screens like UITabBar. I have placed UIButton with Image and Text but, am not able to move the image on top of the button with centre alignment and place the button text in below of the image with center alignment. It should be look like UITabBarItem.
How can I achieve this in UIButton? Anyone can please help me on this? Thanks.
I tried this code but, text not visible and image not properly aligned. Can you please help me?
[self.languageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.languageButton setTitle:#"Language" forState:UIControlStateNormal];
[self.languageButton.titleLabel setFont:[UIFont boldSystemFontOfSize:10.0]];
UIImage *image = [UIImage imageNamed:#"lang_change_white"];
[self.languageButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -image.size.width, -25.0, 0.0)];
[self.languageButton setImage:image forState:UIControlStateNormal];
[self.languageButton setImageEdgeInsets:UIEdgeInsetsMake(-15.0, 0.0, 0.0, -self.languageButton.titleLabel.bounds.size.width)];
Thanks in advance.
your code work fine for me then what is problem ?
plz explein what you want with image and text of the button..?
you have to make 2 special image which contains symbol and text. one image is white image and second one is any color of image . and when user press button set background image as your color image and set initial image as white color image.

Change UIImage base color, keep white

I was trying to use the method outlined here for changing the color of a UIImage used for a UIView. I was hoping this method would ignore whitespace but it does not.
Here is the original image in which I'd like to replace the red with blue.
Here is the code
UIImage *image = [UIImage imageNamed:#"star-badge"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:...];
imageView.tintColor = [UIColor blueColor];
imageView.image = image;
[self.view addSubview:imageView];
but this is the result
is there a way to ignore the white space or only change the red color?
Change the original image so that the middle is transparent instead of white, then the method you're using should work. If need be, display it on a white background.
As David says, you need a transparent star, attached the image how should be just in case you cant handle it on photoshop

UIImage retutns wrong width

I have a UIImageView and I put it in a toolbar. When I run it on the simulator, the image gets stretched in. Meaning the width somehow gets less than the toolBar. Here's my code:
UIImageView *imageNav = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
nav.frame.size.width, nav.frame.size.height)];
nav.image = [UIImage imageNamed:[imageTop objectAtIndex:0]];
This is the output.
http://postimg.org/image/rjirnmiyx/
The yellow is the toolbar and the green thing is the image. It does not fill the toolbar.
Update
Whatever I do, it gets scaled off at the right side. (Like the image above.)
I tried all kinds of content modes and it all came down to one thing. Something does get ruined at the right hand side.
Update 2
I figured out the problem! The problem is that the UIImageView does not have a constraint. Can someone please help me add a constraint?
you can try this
[imageNav sizeToFit];
UIImage *image = [UIImage imageNamed:[imageTop objectAtIndex:0]]
UIImageView *imageNav = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
image.size.width, image.size.height)];
imageNav.image = image;
Hope above code snippet helps..

Setting an background image over an image set for a UIImageView - Objective C

I am setting images to a UIImage programmatically. But I want to also add a play button over that view. Think of Facebook in how there is a play button over the image. That is exactly what I am trying to figure out on what to do. Here is my setting of the UIImage:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg", indexPath.row]];
cell.photoView.image = img;
Suggestions, thoughts?
You can add playbutton either as a UIButton or a UIImageView and add as a subview to your photoview.
[cell.photoView addSubview:urPlayButtonView];

iOS app - Apply background image object to UIView

Can anyone help me understand how I apply a background image object to a UIView please?
I have created a background image which is a blurred version of a background and I would like to apply it to be the background of a uiView in the foreground which would ideally mask the background image.
I have the following code so far -
_blurImage = [source stackBlur:50];
[_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:[_blurImage]]];
I would like to apply the image object(_blurImage) to be the background image of _hpBlurView but i'm struggling to get it working!
At first glance, you are using too many brackets. Here is a working version of your code :
_burImage = [source stackBlur:50];
_HPBlurImage.backgroundColor = [UIColor colorWithPatternImage:_blurImage];
I can't see what stackBlur:50 returns. So start from the beginning. colorWithPatternImag takes UIImage as a parameter. So Start by adding a picture, any picture, to your application. Lets imagine that the image is called image.png. This is one way to do it:
UIImage *image = [UIImage imageNamed:#"image.png"];
_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:image];
This should help to get you going.
Create an image and add to the background.:
UIImage *image = [UIImage imageNamed:#"youimage"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
It's that.
To make sure everything resizes properly, no matter rotation, device size and iOS version, I just set an UIImageView
//Create UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; //or in your case you should use your _blurView
backgroundImageView.image = [UIImage imageNamed:#"image.png"];
//set it as a subview
[self.view addSubview:backgoundImageView]; //in your case, again, use _blurView
//just in case
[self.view sendSubviewToBack:backgroundImageView];

Resources