Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

iphone - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...