Translucent UITableViewCell has no borders - iphone

I created a UITableView. I gave it a background image like this:
UIImageView *imageview1 = [[UIImageView alloc] init];
imageview1.image = [UIImage imageNamed:#"blood2.gif"];
evc.tableView.backgroundView = imageview1;
And then I made the cells translucent by changing them in the tableView:cellForRowAtIndexPath: method:
UIView *backgrView = [[UIView alloc] initWithFrame:CGRectZero];
backgrView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.7];
cell.backgroundView = backgrView;
But now there are no borders around the UITableViewCells anymore. I already set the separatorColor to black but the borders won't show up...

Check with this
[cell.contentView.layer setBorderColor:[UIColor redColor].CGColor];
[cell.contentView.layer setBorderWidth:2.0f];

Related

image in title of navigation bar in objective c

I have made an iPad application, in that I used navigation control,
now in the title bar , I want to put image on left side, so I hide title bar with label, but label is not covering entire width of title bar,
IL APP IN THE SCREEN SHOT,
here is the code snippet,
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 800, 50)];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor yellowColor]; // Change to desired color
titleView.backgroundColor=[UIColor blackColor];
titleView.text = #"IL APP";
titleView.textAlignment=UITextAlignmentCenter;
//self.navigationItem.titleView = titleView;
[self.navigationItem setTitleView:titleView];
[titleView release];
}
#Gama as far as your question is concerned you are asking to put an Image but your real issue being described is that the label is not covering up the title bar. To cover that properly you can use
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 32)];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0];
titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleView.textColor = [UIColor yellowColor]; // Change to desired color
//titleView.backgroundColor=[UIColor blackColor];
titleView.text = #"IL APP";
titleView.textAlignment=UITextAlignmentCenter;
[self.navigationItem setTitleView:titleView];
[titleView release];
}
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
For using an image you can use an image view instead of a label to be assigned as the titleView for navigationItem.
Hope it helps
I tried to solved your problem but I get the same result.
But you can hide navigation bar and add the UILabel in to your ViewController
self.navigationController.navigationBarHidden = FALSE;
[self.view addSubview:titleview];
UIImageView *imageNav = [[UIImageView alloc] initWithImage: [UIImage imageNamed: #"navImage.png"]];
[self.navigationController.navigationBar addSubview:imagenav];
[self.navigationController.navigationBar sendSubviewToBack:imageNav];
[imageNav release];
Hi i wanted to do the same thing and i saw your posting, i basically used some of the code you provided and modified it a little and got it to work see below:
//declare and initialize your imageView
UIImageView *titleImage = (UIImageView *)self.navigationItem.titleView;
titleImage = [[UIImageView alloc]
initWithFrame:CGRectMake((self.navigationController.navigationBar.frame.size.width/2)
- (100/2), 0, 100, self.navigationController.navigationBar.frame.size.height)];
//setting the image for UIImageView
titleImage.image = [UIImage imageName:#"photo.jpg"];
//NOTE: you have to do this line at the bottom to add image to the navigation bar Try it it WORKS!
self.navigationItem.titleView = titleImage;

How to add an image subview to a tableview programmatically

I'm new to programming, and I know how to add a static image behind a tableView in a .xib file, but not in code. I have tried the following code:
UIImage * image = [UIImage imageNamed:#"pic.png"];
[self.view addSubView: image];
but nothing happens when I write this!
To display an UIImage you have to use an UIImageView and put it under the UITableView using the same frame. Don't forget to set the table view's background to transparent.
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"pic.png"]];
iv.frame = CGRectMake(0.0, 0.0, 300.0, 600.0);
UITableView *tv = [[UITableView alloc] initWithFrame:iv.frame style:UITableViewStylePlain];
tv.opaque = NO;
tv.backgroundColor = [UIColor clearColor];
[self.view addSubView: iv];
[self.view addSubView: tv];
[iv release];
[tv release];
You need to use a UIImageView, not a UIImage. Also, when adding a view programmatically, don't forget to set the frame.

UITableView cell takes pattern color of UITableView's background image

I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:
The background image shell look like this:
*pay attention to white circles that disappear under the cells!
My code is as follws:
in viewDidLoad i set the background image of table view:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"general_bg.png"]];
For each cell i remove any background color like this:
UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bckView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bckView;
cell.backgoundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)];
textLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textLabel];
line separators are custom images added to cells.
Instead of setting the BackgroundColor attribute of the tableview, try setting the backgroundview:
UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds];
background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
self.tableView.backgroundView = background;
This should fix the issue of the cell's taking on the same image as the background.
self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
maybe this is what you're looking for

UITableViewController background image stretched

I'm trying to set the background image for a UITableViewController. I've got the following code which does set the background fine, but the image itself is being stretched to about twice the usual size.
[[self view] setAutoresizesSubviews:NO];
UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Default.png"]];
self.tableView.backgroundView = backgroundView;
self.tableView.backgroundColor = [UIColor clearColor];
[backgroundView release];
The image is only 640x960 pixels.
I've tried manually setting the frame of the backgroundView but it doesn't change the size of the background image.
Can anyone explain where I'm going wrong?
Many thanks.
In my expirience, you should avoid using
[UIColor colorWithPatternImage: ... ];
as it leads to some problems with picking the right image for Retina/Low-Res devices.
Try something more like this:
UIImageView* bgView = [[[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"Default.png"]] autorelease];
[tableView.backgroundView addSubview:bgView];
Also make sure you have two PNGs:
Default.png - 320 x 480
Default#2x.png = 640 x 960

How to make semi-transparent UITableViewCells?

I hope to add image to cell background and from the semi transparent cell I could see the backgroud of tableview.
From following topic, I know how to make transparent cell.
UITableViewCell transparent background (including imageView/accessoryView)
I've tried above, it did work. But when I add the following code:
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha: .4];
cell.backgroundView = backView;
The cell became grey color without any transparency, if I change code as follows,
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
The cell became white, still without any transparency.
Is there one can give me any clues?
To make your UITableViewCells Semi-Transparent that is Translucent, you have to make your UITableViewCells Transparent and then, set cell's backgroundView to an image which has translucent properties. Also set selectedBackgroundView of the cell to an image which is translucent and gives a selected cell's effect.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.text.backroundColor = [UIColor clearColor]; //if you have labels on cells..
cell.backgroundView = backView;
Then set an image with translucent effect on our transparent cell..
UIImageView *cellImage = [[UIImageView alloc] init];
[cellImage setImage:[UIImage imageNamed: #"unselectedCellImage.png"]];
[cell setBackgroundView:cellImage];
[cellImage release];
Then set an image for selected cell to give an translucent effect after selection also..
UIImageView *cellImageSelection = [[UIImageView alloc] init];
[cellImageSelection setImage:[UIImage imageNamed: #"selectedCellImage.png"]];
[cell setSelectedBackgroundView:cellImageSelection];
[cellImageSelection release];
It'll work..
Cheers..
You can try this one
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha: .2];
cell.backgroundView = backView;
What you did wrong was you choose .1 .1 .1 which is for black color you need 255 255 255 for the white color and your opacity was very high so it looked gray color to you actually it was black with opacity. Hope this helps :)
Views are initialized as opaque by default, so you probably need to explicitly set backView.opaque = NO; in order for it to draw with any transparency.