如何重新创建与默认tableView:viewForHeaderInSection:相同的默认UIView? [英] How to recreate the default UIView the same as the default tableView:viewForHeaderInSection:?

查看:149
本文介绍了如何重新创建与默认tableView:viewForHeaderInSection:相同的默认UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试实施

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

要获得黑色部分而不是白色部分中标题的文本标签,但它看起来与SDK创建的默认标签有很大不同,我的外观很难看.

to get the text label of the header in section of black color instead of the white color, but it looks so different from the default one created by the SDK, mine is so ugly.

如何重新创建与SDK中的UIView完全相同的UIView?

How to recreate the UIView with exactly the same as the one from the SDK?

摘自Apple文档:

Discussion
The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView:viewForHeaderInSection: instead.

推荐答案

尽管这并不完全正确,但我发布此信息的目的是希望有人可以改进我的方法.文本是正确的(默认为白色,但您可以更改).背景渐变和不透明度不够完美(太亮了??)-可能需要在此处进行一些调整.

Although this is not exactly right, I'm posting this in hopes that someone can improve upon my approach. The text is right (white like default, but you can change that). The background gradient and opacity are not perfect (too light??)--some tweaking here might be needed.

在此处获取sectionheaderbackground.png: http://img5.imageshack.us/img5 /6616/sectionheaderbackground.png

Get the sectionheaderbackground.png here: http://img5.imageshack.us/img5/6616/sectionheaderbackground.png

// Create a stretchable image that emulates the default gradient
UIImage *buttonImageNormal = [UIImage imageNamed:@"sectionheaderbackground.png"];
UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];

// Create the view for the header
CGRect sectionFrame = CGRectMake(0.0, 0.0, 320.0, 22.0);
UIView *sectionView = [[UIView alloc] initWithFrame:sectionFrame];
sectionView.alpha = 0.9;
sectionView.backgroundColor = [UIColor colorWithPatternImage:stretchableButtonImageNormal];

// Create the label
CGRect labelFrame = CGRectMake(10.0, 0.0, 310.0, 22.0);
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:labelFrame];
sectionLabel.text = @"Test section label";
sectionLabel.font = [UIFont boldSystemFontOfSize:18.0];
sectionLabel.textColor = [UIColor whiteColor];
sectionLabel.shadowColor = [UIColor grayColor];
sectionLabel.shadowOffset = CGSizeMake(0, 1);
sectionLabel.backgroundColor = [UIColor clearColor];
[sectionView addSubview:sectionLabel];
[sectionLabel release];

// Return the header section view
return sectionView;

这篇关于如何重新创建与默认tableView:viewForHeaderInSection:相同的默认UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆