Hoa*_*ham 7 iphone objective-c uitableview
我试着实现了
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
获取黑色部分的标题的文本标签而不是白色,但它看起来与SDK创建的默认颜色不同,我的丑陋.
如何重新创建与SDK中的UIView完全相同的UIView?
来自Apple文档:
讨论
表视图对节标题标题使用固定字体样式.如果需要不同的字体样式,请在委托方法tableView:viewForHeaderInSection中返回自定义视图(例如,UILabel对象).
小智 13
虽然这不完全正确,但我发布这个是希望有人可以改进我的方法.文本是正确的(默认为白色,但您可以更改).背景渐变和不透明度并不完美(太亮了) - 这里可能需要进行一些调整.
在这里获取sectionheaderbackground.png: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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4244 次 |
| 最近记录: |