Setting background on UITableViewController - ios

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;

Related

IOS/Objective-C: Change tint of an image view

I would like to change the color of an image view when the user touches it. I don't need it to change a great deal. However, I would like it to change to a shade of blue. I found the following code to change the gradient but it is not having any effect. I don't need a gradient, actually, only a tint. Would appreciate any suggestions.
UIView *snapshot = [[UIImageView alloc] initWithImage:image];
snapshot.layer.masksToBounds = NO;
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = #[(id)[UIColor redColor].CGColor, (id)[UIColor blackColor].CGColor];
[snapshot.layer insertSublayer:gradient atIndex:0];
An easy and non-intrusive way is to add a translucent overlay to your image view. This can then be shown and hidden as the button is pressed and released.
- (void)indicatedImageViewPressed:(UIImageView *)imageView on:(BOOL)on {
UIView *overlay = [imageView viewWithTag:1]; // See if already created
if (overlay == nil) {
overlay = [[UIView alloc] initWithFrame:imageView.bounds];
overlay.tag = 1; // Mark view to find it next time
overlay.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.3]; // Your color overlay goes here
[imageView addSubview:overlay];
}
overlay.hidden = !on;
}
You can try giving the UIImage a tint
UIImage *image = [[UIImage imageNamed:#"Your Image"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.tintColor = [UIColor clearColor]; // Or any color really you'd like would work
imageView.image = newImage;
And then changing that tint when the user touches the image using a tap gesture recognizer

UITableView weird separator line color

i have a problem in setting UITableViewCell background color. I wanna change it into my own color, so I use this code to change that background color :
UIView *bg = [[UIView alloc] init];
bg.backgroundColor = [ColorManager backgroundInput];
bg.layer.masksToBounds = YES;
[cell setSelectedBackgroundView:bg];
I implement this code in CellForRowAtIndexPath method.
The weird thing I have is, when i tap into a cell, the separator line color being highlight just like the image below. I just wanna make it still dark, anybody have idea?
Thank you
After setting up your own background view,which will have the line or not,
you can clear the default tableview color
tablename.separatorColor = [UIColor clearColor];
OR
If you don't want to remove the default line then you can give same color of background view to line color
//You can specify the RGB of background view
tablename.separatorColor = [UIColor colorWithRed:R green:G blue:B alpha:1.0f];
I think the best option is
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Another option is to set the backgroundColor of the UITableViewCell to a clear color.
cell.backgroundColor = [UIColor clearColor];
try it
Objective-c
tablename.separatorColor = [UIColor blackColor];
Swift
tablename.separatorColor = UIColor.blackColor();

How to make immovable background in iOS?

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;

UIImageView backgroundColor colorWithPatternImage not showing

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.

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