change table view's cell selection color - iphone

can we change the selection color of table view, i.e cell, by default its blue, so, can we change it to any other color?
regards

this way in code
aCell.selectedBackgroundView = [[[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"selectedBackground.png"]] autorelease];
or you can set it in interface builder to gray, I think blue and grey is all that is available without creating a be view

Another way to do this, that doesn't require an image file is:
UIView *bgView = [[UIView alloc] init];
// At least on iOS6 you don't to size the view for this to work.
bgView.backgroundColor = [UIColor grayColor];
aCell.selectedBackgroundView = bgView;

Related

How to make cell transparent on selection

I have a custom UITableView with its clearColor background. I'm setting the cell's backgroundView to a transparent UIImageView and setting the background image view's backgroundColor to [UIColor clearColor]. I'm also setting the cell's backgroundColor to [UIColor clearColor].
I want to make cell.backgroundview as transparent on selection. How to do that?
you can explicitly set a selectedBackgroundView property of the cell with a semitransparent or transparent content (UIimageview) so that i will not become opaque on selection
http://www.youtube.com/watch?v=PwcBdCUZNWs
i think thats what u r asking for just make the selectedView transparent from the UI properties
In your Cell creation :
cell.selectedBackgroundView =[[UIImageView alloc] init];
((UIImageView *)cell.selectedBackgroundView).image = [UIImage imageNamed:#"your transparent UIImage"];
or:
UIView *v = [[UIView alloc] init];
v.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = v;

how to change the background of table view , quickdialog box

I am following the tutorial about a quick dialog box to create a form as below
Now, I would like to change the background of this form. Does anybody know how to achieve this, please advice me on this.
Thanks
Try this, if you want to show an image as a background:
tableView.backgroundColor = [UIColor colorWithPattern:#"your_image_here"];
or
tableView.backgroundColor = [UIColor colorWithRed:128 green:128 blue:128 alpha:1.0];
If this does not work, you can set the backgroundView property of the table view:
tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"your_image_here"]]] autorelease];
Use the backgroundView property of the UITableView.
If you want to use an image, just create a UIImageView and set backgroundView to it.
UIImage *myImage = [UIImage imageNamed:#"foo.png"];
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:myImage];
You may also use the contentMode to adjust how the image fits in the view.
self.tableView.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
You could try some of the properties that UITableView either inherits or declares:
#property(nonatomic, readwrite, retain) UIView *backgroundView
#property(nonatomic, copy) UIColor *backgroundColor
The first is probably what you are going to want. It is declared by UITableView. The second is inherited from UIView.
If you're setting a background colour try this...
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor]; //replace with your colour
But if you want a pattern image don't use that method... Do this..
tableView.backgroundColor = [UIColor clearColor];
UIView *v = [[UIView alloc] init]; //needs memory Managment (arc example)
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"pattern.png"]];
tableView.backgroundView = v;
This is because if the UITableView is group styled the and you have a patterned background image as the tableviews backgroundColor then it's applied to the edges of the cells too but as they're separate views the pattern becomes incorrect.
Hope it helps.
Try to set the background color of the table view; it may require that you change the table view style from grouped to plain.

Set background image in table view when story boarding is also used

I am doing the following to set the background image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImageimageNamed:#"appback_new.png"]];
[self.tableView setBackgroundView:imageView];
in view did load method. Also, I made sure that the background color is set to clear color in story board.
But when the view loads, it loads with a black color.
Did any one face this issue and knows how to resolve it?
Thanks.
Try this it should work :
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"appback_new.png"]];
self.tableView.backgroundColor = background;
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"appback_new.png"]];
try your code after inserting this line of code
tableView.backgroundColor = [UIColor clearColor];

How to set UITableView background to image?

I've noticed that a number of apps have a custom background image for UITableView (or have set the background to a color.)
I can't find any API in the UITableView class to affect this, and my attempts in interface builder have failed (trying to set the color of the UIView)
Any suggestions? I've seen a third party app with pictures, so I know it can be done.
I just ran into the same question myself, but I found a way to do it that TomSwift touched on. As he mentioned, UITableView has a backgroundView property that is intended to do just what you're looking for. If you want to set the background color, you should instead use the backgroundColor property, as others have said. So:
// Set an image as the background of a UITableView called 'tableView'
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"MyImage.png"]];
[tableView setBackgroundView:bg];
or:
// Set a solid color as the background of a UITableView called 'tableView'
// In this case I chose red
[tableView setBackgroundColor:[UIColor redColor]];
add this line in you code where you want to set background color for your image
[YourView(or imageView) setbackgroundColor:[UIColor
groupTableViewBackgroundColor]];
Thanks
UIImageView *image = [[UIImageView alloc] initWithImage:
[UIImage imagenamed:#"no_image.png"]];
[self.view addSubview:image];
UITableView *tableview = [[UITableView alloc] init];
[image addSubview:tableview];
tableview.backgroundcolor = [UIColor clearColor];
try this. it works for me.
CALayer *background = [CALayer layer];
background.zPosition = -1;
background.frame = self.view.frame;
background.contents = [[UIImage imageNamed:#"background.jpg"] CGImage];
[tableView.layer addSublayer:background];
you need to add an image view and set the table background color to clear color see this link for tutorial
Set the backgroundView property of the tableView. You can set it to a view where you have set a custom backgroundColor, or you can set it to a UIImageView where you've set an image.
alternative solution of GhostRider
No coding
Make UiImageView by the interface builder,
put your image in resources.
set it in UIImageView Image property by the use of Inspector.
select table view and set it background color to clear(for this make opacity to 0 by using attribute inspector).
This is how I did it. Probably not the best way, but works well enough.
UIImage *bg = [UIImage imageNamed:#"bg"];
[bg drawInRect:self.view.window.frame];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.window.frame];
bgView.image = bg;
activityTable.backgroundView = bgView; //activityTable = UITableView

Navigation bar (iphone)

I have created email functionality view in which everything is working fine, but the color of a navigation bar item is not changing like other views. I have used below code for navigation color but 1 navigation bar button item is left with default color. How do I change it?
controller.navigationBar.barStyle = UIBarStyleBlack;
How about use this?
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
of course on your viewDidLoad
Do you create the bar button item yourself? If so, you can change its background color by making sure it's a "custom view" type button item:
// Assuming you have some predetermined width w and height h
UIView *backgroundView = [[[UIView alloc]
initWithFrame:CGRectMake(0.0, 0.0, w, h)] autorelease];
backgroundView.backgroundColor = [UIColor blackColor];
UIBarButtonItem *myItem = [[[UIBarButtonItem alloc]
initWithCustomView:backgroundView] autorelease];
Then you can change the background color at a future date by setting the backgroundColor property on the bar button item's customView:
myItem.customView.backgroundColor = [UIColor yellowColor];