views:

606

answers:

2

Hi everybody,

I have a plain UITableView in my iPhoneApp. I would like to change the font size of the header text. I understand that this is not possible and that I need to create my custom header with my own label.

I just wonder if anybody knows how I can reproduce a header similar to the standard one (using the same background image,etc...)? I can not find the background image anywhere..

Best regards, Jonathan

+1  A: 

You're looking for [UIColor groupTableViewBackgroundColor]:

[view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
Can Berk Güder
Sorry I think I explained myself wrong. I meant the section header (blue background) in plain mode for the UITableView.It seems it is an image and not the colour. I'm not really good with graphics so I was wondering if I could find the image somewhere to reuse it...Regards,Jonathan
Hmm, I don't know if you can obtain that image, but even if you could, it would probably be fixed size, so you wouldn't want to use it.
Can Berk Güder
A: 

It won't stretch REALLY high, because it will look bad, but this can get you out of dodge, create a stretchable image which uses a graphic of the original header (any iphone template png/psd has these readily extractable).

Then

UIImage *image = [UIImage imageNamed:@"tableHeader.png"];
UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:5.0 topCapHeight:2.0];
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:frame];
[backgroundImage setImage:stretchImage];

and either return that as part of the UIView you construct in your:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

method or (better still) add it as the background of whatever UIView subclass instance you're returning in that method.

Clearly, any width works, I've found I can get it up to 55pixels high without looking naff. Best answer is to replicate the gradient.. I'm too nooby for that though :)