Title for section in UITableView - remove text shadow? - iphone

I have a grouped UITableView with black background color.
Thus the gray section headers with the white drop shadows are unreadable.
Next thing to know, the section height varies depending on language and section.
How to solve this the most easy way ?
If I implement viewForHeaderInSection I also need to implement heightForHeaderInSection, but the height varies (several sections with different title and different language => different text length/view height)

You need to dynamically determine the height of the cell, and set your label so that it autosizes itself.
Hope this link will be helpful to you.
All the best.

I had the same issue in 6.1. This worked for me:
- (void) viewDidLoad {
[super viewDidLoad];
[self.tableView setBackgroundView:nil];
self.tableView.backgroundColor = [UIColor blackColor];
[[UILabel appearance] setShadowColor:[UIColor clearColor]];
[[UILabel appearance] setTextColor:[UIColor lightGrayColor]];

Related

adding image in UILabel in iPhone

i have UIlabel with image.my text are won't come into top of the image i want to show my text in top of the image.
image1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"salarytax.png"]];
this is my code to adding image to label. this image is a output of that code. how can i show the text in top of the image
try adding the UILabel on the image
[myimageview addSubView: myLabel];
[myImageView bringSubviewToFront: myLabel];
If you have just taken the UILabel and trying to set its background as an image then dont think it would create a problem.
If you are able to view the text on the label but you want the text to be vertically on top then you can set its contentVerticalAlignment property to top.
Hope this helps..
UILabel *imageLabel;
[imageLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"logo.png"]]];
[imageLabel setText:#"Khalid Usman"];
[imageLabel setTextColor:[UIColor blackColor]];
Note: I have checked it for conformation then i post. It's working.

UITextField added to contentView of UITableViewCell does not display properly in Popover (iPad, iOS 4.2)

I'm trying to display a table of choices in a popover on the iPad. I'm adding a UITextField to the default UITableViewCell. The table is configured as a sectioned table.
It does not draw correctly and is not displayed.
If the row is selected, the UITextField becomes visible. If you click another row, it disappears.
I've played with subview order to no avail. What has worked has been to set UITableViewCell.backgroundColor = [UIColor clearColor].
If I do that, I think need to set the color somewhere else such as the content view, UITableViewCell.contentView.backgroundColor = [UIColor whiteColor];
However, it still does not display correctly. It looks fine when its not selected, or selected. But if I programmatically set an accessory checkmark, half of the background of the accessory checkmark shows up clear with the darker color of the table background.
If the row is selected, it looks ok, but if another row is selected, as the row with the UITextField is being de-selected, for a fraction of a second, you see half of the accessory background clear (transparent).
Any ideas or suggestions of what might be wrong or how to work around this? The Apple docs clearly state that adding a view to the ContentView is an appropriate way to implement it, yet it does not appear to work in this case.
Here's the code I currently have within tableView:cellForRowAtIndexPath:
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(130, 10, 60, 26)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.text = #"foo";
[cell.contentView addSubview:textField];
[textField release];
cell.contentView.backgroundColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
In general the place to set a UITableViewCell's backgroundColor is not tableView:cellForRowAtIndexPath:. You must do it in +tableView:willDisplayCell:forRowAtIndexPath:+.
You should not need to change the contentView's backgroundColor.

UITableViewCell color issues with custom table view background

I have a UITableView with a custom background image set like this:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]];
The background appears fine, but my UITableViewCells (default cells, not custom) have some sort of weird tint to them, and the UILabel containing the "New Project" text also seems to have some sort of background behind it. How can I remove this? I've already tried:
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
Thanks
alt text http://cl.ly/Cg5/content
I believe that this is a nasty side-effect of simply adding an image straight into your table view's backgroundColor.
Try adding the image to the view's background color:
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]]];
and then set the table view's backgroundColor to be clear:
[[self tableView] setBackgroundColor:[UIColor clearColor]];
I hope this helps!
Some times when your working with setting images for an app, and testing on the simulator, they get frozen to the app for the few run. Not sure, this is the case even if you delete the image files; they still keep popping up.
I would make that you have rest the simulator, and restart Xcode. Then force a rebuild of the app back on the simulator. This should clear out any images- even background images if they are still being referenced.
If this is not a solution that works...try making sure that you don't have conflicting commands going to the same UiTablView object-(1 from IB and 1 from Xcode programmically). Sometimes you can overlook that you have set something in IB, and it conflicts with what your telling it to do programically.
If that doesn't solve the issue...check the connections in IB and make sure your reffrencing the correct IBOutlet UITableView *tableview. And you have the delegat and data protocols in the header.
If you want to have each cell set with background and want to remove text's background, maybe you can try this...
- (void)viewDidLoad {
...
self.tableView.backgroundColor = [UIColor clearColor];
...
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
...
}

How do I set a background image for a grouped table view?

I've seen some iPhone applications that use a custom image as the background for a grouped UITableView, instead of the standard gray lines.
How is this achieved?
Here's what worked for me (and fairly simple once I figured it out ;)
1) Add a view in your app delegate and make it a subview of the window:
UIView *bgView = [[UIView alloc]initWithFrame:window.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"screenBG.png"]];
[window addSubview:bgView];
[bgView release];
2) On each view controller .m file, under ViewDidLoad, set background color of that particular view to transparent (so the other bgView created above will show through):
self.view.backgroundColor = [UIColor clearColor];
And in my case, the view controller in step 2 was a tableviewcontroller. Looks great.
And BTW, doing the following in each view controller did NOT work well:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"screenBG.png"]];
So follow steps 1 and 2 above.
Hope this helps out,
Tbone
Try this
- (void) viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"wallpaper.png"]];
self.tableView.opaque = NO;
}
In another project (developed using 2.2.1) I did this by setting my UITableView's background opacity to 0%, and then simply layering a UIImageView behind it using Interface Builder. This allowed me to have a fixed background regardless of the table state. You can also set the background of the UITableView to be an image instead, but then the background scrolls with the table. (I don't have the code handy at the moment, but I got the tip a while back on the Apple developer forums).
Note that this can cause some performance issues. Apple discourages using transparency whenever possible because the GPUs on the pre-3GS models aren't particularly beefy.
You can use the +[UIColor colorWithPatternImage:(UIImage)] method like so:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
the problem with colorWithPatternImage: is that you need to use "patterned" images, otherwise your image will be tiled randomly
this link has a simple solution, if you want all your views to have the same background
http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"SortByCategory_320x480.png"]];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor clearColor];
Hope this will help. It won't display hideous translucent background behind the cells especially in case of Grouped UITableView.

can i use highlighted the table view cell without default blue color in objective c?

I doing a project where i need to use highlighted table view color not default.
Of course you can.
There are two methods to achieve this:
Use UITableViewCell's selectedBackgroundView and selectedTextColor properties
Subclass UITableViewCell and implement the drawInRect and setSelected:animated: methods
The latter option gives you more flexibility and much better performance, but it might be slightly harder if you haven't used CoreGraphics before.
UPDATE In response to the OP's comment:
Here's how you can use the selectedBackgroundView property:
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[bgView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgView];
[bgView release];
I haven't tried this myself, but it should work.
Try referring to this demo - maybe you could have a look at it and get some help.