Accessory View image not highlighted when row selected - ios

I have added an accessoryView UIView in my UITableCell when cellForRowAtIndexPath is called.
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"flechalinterna.png"]];
cell.accessoryView.backgroundColor=[UIColor clearColor];
But when the user selects row at index path, the accessory view is not highlighted. I tried to avoid it setting the background color to clearColor but it does not make any difference. Getting the following effect shown in this image:

Try to use this one
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"flechalinterna.png"] highlightedImage:[UIImage imageNamed:#"flechalinterna.png"]];

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

Disable highlight button in uitableviewcell when select row

I have custom UITableViewCell and two buttons inside. When I select row, background for buttons change for the same color as background of selected row, and border for buttons disappears.
How Can I disable change border/background color for button when row is selected ?
Thanks for reply
1) Create a UIView and assign the desired background color.
2) Render the UIView to an UIImage
3) Set the backgroundImage of the button for the desired state.
UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
colorView.backgroundColor = color;
UIGraphicsBeginImageContext(colorView.bounds.size);
[colorView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[button setBackgroundImage:colorImage forState: UIControlStateHighlighted];
I achieved this using a clear background view for my cells and disabling selection color of the row, but I needed it that way. Don't know if it suits your need, but you can try this:
UIView *selectedView = [[UIView alloc] initWithFrame:cell.bounds];
selectedView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = selectedView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Hope this helps.
Do checkout this thread as well : Why do all backgrounds disappear on UITableViewCell select?

How can I insert an imageView behind a UITableView in a fixed position (no scrolling)?

I am trying to insert an image behind my table view using:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"newpink120"]];
imageView.frame=CGRectMake([[UIScreen mainScreen]bounds].size.width-60, [[UIScreen mainScreen]bounds].size.height-60-self.navigationController.navigationBar.frame.size.height, 60, 60);
[self.tableView addSubview:imageView];
[self.tableView sendSubviewToBack:imageView];
This seems to work but the image scrolls with the table. Is there anyway to keep it fixed in the bottom right corner?
For creating a static tableview background, you have to do 2 things
1) set self.tableView.backgroundColor = [UIColor clearColor];
2) and then initialise the table background view with an UIImageView and set the image you want to show there.
[self.tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]] ];
Your image scrolls because it has been added in the tableview content and when you scroll the tableview, all the content scrolls.
But you can add the image in the superview of your tableView, behind it.
For example, if the tableView is in self.view you can try :
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"newpink120"]];
imageView.frame=CGRectMake([[UIScreen mainScreen]bounds].size.width-60, [[UIScreen mainScreen]bounds].size.height-60-self.navigationController.navigationBar.frame.size.height, 60, 60);
[self.view addSubview:imageView];
[self.view bringSubviewToFront:self.tableView];
(Make sure that the tableView has a clear backgroundColor.)

custom UITableViewCell with image for highlighting

I have a custom UITableViewCell (instantiated from XIB) with an image as background. Now I want another image to be the background when the cell is selected (similar to the blue flashing for standard cells). I already tried setting it using setSelectedBackgroundView in (void)setSelected:(BOOL)selected animated:(BOOL)animated or even in didSelectRowAtIndexPath but the background for highlighting wont show up. What am I doing wrong?
In your Custom Cell.xib
Next make this
And Finally do this
have you tried like below one
Call below Method From the TableView DataSource Method (cellForAtIndexPath) For Doing the same Task
- (void)setCellBGColorNormalAndSelectedForTableViewCell:(UITableViewCell*)cell cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UIImageView *normalCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[normalCellBG setImage:[UIImage imageNamed:#"box_nonselected.png"]];//Set Image for Normal
[normalCellBG setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:normalCellBG];
UIImageView *selecetedCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[selecetedCellBG setImage:[UIImage imageNamed:#"box_selected.png"]];//Set Name for selected Cell
[selecetedCellBG setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:selecetedCellBG ];
}
You can set selected background view using the XIB you created for CustomCell . You just need to take UIImageView on to the that XIB (imageview must have same height as that of CustomCell) . Now connect the outlet naming "selectedBackgroundView" for that CustomCell to the UIImageView you have taken as a selected background view . Also check whether the selectionStyle for that CustomCell is not none .

Place an UIImageView behind the tableView in a UITableViewController Subclass

I am trying to place a UIImageView behind a the tableView in a view controller that is a subclass of UITableViewController. I have gotten the following code to sort of work, but the image scrolls with the rows in the table.
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[backgroundView setImage:[UIImage imageNamed:#"woodbackground1"]];
[self.view addSubview:backgroundView];
[self.view sendSubviewToBack:backgroundView];
[self.tableView setBackgroundColor:[UIColor clearColor]];
I tried the suggestions in this post
Add UIView behind UITableView in UITableViewController code but they produce the same result, am image that across with the table.
Is there a way to place the image view behind the tableview so that the image does not move with the table?
Thanks,
Dan
Why not use
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background"]];

Resources