UIImageView backgroundColor colorWithPatternImage not showing - ios

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.

Related

Background Image overlaps Refresh Control

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

Setting background on UITableViewController

I have TableViewController with many cells. And background of my TableView Default White. I want to become some background image. I see this code :
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundPattern.png"]];
but i can`t use this on swift. So help me recycle this code to swift code or give your solution to this problem
Try this code :
self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "BackgroundPattern.png")!)
You need to set the background colour of each cell to clear colour.
In your cellForRowAtIndexpath method, add: cell.backgroundColor = [UIColor clearColor]
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:YOUR_IMAGE]];
self.tableView.backgroundColor = background;
or
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:YOUR_IMAGE]];
[imgView setFrame:self.tableView.frame];
self.tableView.backgroundView = imgView;

ios Change background of static TableView

I'm trying to put a background image into a UITableViewController with static cells inside.
Usually, in normal UIViewControllers I do this by changing the UIViewController's background color and setting the tableview's background color to clearcolor and opaque to NO
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"defaultBackground.png"]];
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
but doing this in my UITableViewController with static cell's leaves me with a transparent tableview with a black background. It seems like there is no view underneath.
I tried to add the view and make it contain the tableview, but this leaded to an empty view without the tableview.
self.view = [UIView alloc]initWithFrame:self.tableview.frame;
[self.view addSubview:self.tableView];
[self.view bringSubviewToFront:self.tableView];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"defaultBackground.png"]];
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
Is there a way to fix this?

Setting UITableView backgroundColor in universal app (iOS 5)

I have to set the backgroundColor property of a UITableView to a certain color in my universal app. If I write this...
self.tableView.backgroundColor = [UIColor colorWithRed:146.0f green:197.0f blue:240.0f alpha:1.0f];
...it doesn't work on iPhone nor iPad (background results white).
If I use a standard color, instead...
self.tableView.backgroundColor = [UIColor greenColor];
...it works on iPhone but not on iPad.
I tried other solutions suggested on SO (backgroundView to nil/clearColor, etc.), but none of those works on iOS SDK 5. Can you help me?
You need to divide each color value to 255.
Your color will be:
[UIColor colorWithRed:146/255.0 green:197/255.0 blue:240/255.0 alpha:1.0];
Instead of changing the background color, you can set a backgroundView (with the background color that you like) for the tableView.
UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.bounds];
bgView.backgroundColor = [UIColor redColor];
self.tableView.backgroundView = bgView;
Are you using a navigation controller?
Try this:
self.tableView.backgroundColor = [UIColor clearColor];
[self.tableView setSeparatorColor:[UIColor clearColor]];
self.navigationController.view.backgroundColor = [UIColor greenColor];
Thats what I use with iOS5 and an universal app.

Dark Corners UITableViewController

I have a UITableViewController. In viewDidLoad, I do the following:
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
The background is supposed to be a gradient. Two issues:
Gradient seems to get cut off at the end of the UITableView.
The corners are tinted.
I've experimented with setting the UITableCell's opacity to NO, but that doesn't worked. I have read these threads already: Transparent background in grouped UITableView - iPhone, and Black corners around UITableViewCells.
I'm not using Interface Builder at all for this.
Example:
Make a UIView with that pattern image as background color and set it as table view's background view.
UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
self.tableView.backgroundView = bgView;
[bgView release];

Resources