In xcode 7.1, I have used the refresh control feature of a TableView.
I have also used the following code to set an image to the background
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
[tempImageView setFrame:self.tableView.frame];
self.tableView.backgroundView = tempImageView;
This image overlaps the activity indicator on the app so you can't see if its working. Is there a way to put the activity indicator back on top?
Thanks
Use this line
self.tableView.backgroundColor =
[UIColor colorWithPatternImage:[UIImage imageNamed:#"image.png"]];
Instead of using
self.tableView.backgroundView = tempImageView;
Note: but your UIImage size should be greater/equal to UITableView size
Related
I'm currently setting the backgroundView of my UITableViewCells to images being pulled from eBay's API.
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageWithData:imageData] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
[cell setNeedsLayout];
The problem is that the table tries to squeeze the image to fit the height of the cell as you can see below:
What I want it to do is to only show the middle section of the image in the cell, as you can see below. Is there any way to do this?
When you add the Imageview as a backgroung view of cell have to set the content mode of the image before setting to the cell background view:
Try the following code and let me know.
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageWithData:imageData]];
imageView.contentMode = UIViewContentModeCenter;
imageView.clipsToBounds = YES;
cell.backgroundView = imageView;
I've seen on many forums that you shouldn't use colorWithPatternImage for memory issues, you should use UIImageView if you are using a large background image and add as a subview to save memory. I tried with these three solutions and all of those are showing same memory used:
// First Option
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Background"]];
[self.view addSubview:backgroundView];
[self.view sendSubviewToBack:backgroundView];
//Second Option
UIImage *image = [UIImage imageNamed:#"Background"];
self.view.layer.contents = (id) image.CGImage;
//Third Option
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background"]];
I am using iOS7 SDK. Is there anything I am missing or have iOS7 improved in this direction?
In my application, I have UITableViewController, with table on it.
I filling background with image in this way:
UIImage* backgroundImage;
backgroundImage = [UIImage imageNamed:#"bg.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
But, background moves with all other view controller components, while user scroll the table.
Is it possible, to make immovable background, like HTML background?
Thanks.
Try
UIColor *color= [[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Background.png"]] autorelease];
self.tableView.backgroundColor = color;
or
UIImageView *imageView= [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Background.png"]] autorelease];
imageView.frame = self.tableView.frame
self.tableView.backgroundView = imageView;
I'm having an issue with UIImageView that's not quite making sense to me. I want to set the image of the UIImageView and have it appear above the patterned image I've set to the background. This occurs correctly if the background color is a standard color: [UIColor whiteColor], but as soon as set it to a patternImage the background becomes completely transparent. This is kind of frustrating. I can get around it by creating another view, setting the backgroundColor of it to a patternImage, and then adding the UIImageView as a subview, but that's creating an extra view that should be unnecessary, IMO. Here's my code:
UIImageView *view = [[UIImageView alloc] initWithFrame:_standardRect];
view.image = _connectIcon;
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.jpg"]];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
return view;
Doing this works on iOS 5.1:
view.layer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.jpg"]].CGColor;
However, the bug is gone on iOS 6.
I want to display a number on image like badge of size 30*28, which is placed upon button image,
I have an badge image to set up on the top of button image..
on top of badge image I should able to display text or number and my badge size is 30*28.
so, for this to achieve I want to set a label on top of my button image and so I want to set label background to some image called badge image.
found this in stack overflow itself as the above code just gives the background without the label
was useful for me
so sharing
theLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"blah"]];
See: Adding Background image to UILabel
You can't add a background image to a UILabel, but you can add a UIImageView as a subview to a UILabel. Make sure the UILabel has backgroundColor = [UIColor clearColor]; for transparency.
E.g.
UIImageView *labelBackground = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"mybg.png"]];
[myLabel addSubview:labelBackground];
[labelBackground release];
myLabel.backgroundColor = [UIColor clearColor];
Should work. Untested.
To make the image fit in your UIview, try this code
UIImage *backgroundImage = [UIImage imageNamed:#"imageNameHere"];
UIGraphicsBeginImageContext(self.labelName.frame.size);
[backgroundImage drawInRect:CGRectMake(0, 0, self.labelName.frame.size.width, self.labelName.frame.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.labelName.backgroundColor = [UIColor colorWithPatternImage:newImage];