自定义Section:修改UITableView的Section的背景和字体
2011-08-04 23:46
567 查看
自定义Section:修改UITableView的Section的背景和字体
第一次尝试修改UITableView的Section的背景和字体,头疼好一阵,终于找到了方法:
如同自定义Cell一样,使用UITableView的函数,可以自定义Section:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
例子代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(12, 0, 300, 22);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor MujiLightTextColor];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
[sectionView addSubview:label];
return sectionView;
}
第一次尝试修改UITableView的Section的背景和字体,头疼好一阵,终于找到了方法:
如同自定义Cell一样,使用UITableView的函数,可以自定义Section:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
例子代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(12, 0, 300, 22);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor MujiLightTextColor];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
[sectionView addSubview:label];
return sectionView;
}
相关文章推荐
- 自定义Section:修改UITableView的Section的背景和字体
- 设置UITableView Section的背景颜色和字体颜色-自定义Section
- IOS_设置UITableView Section的背景颜色和字体颜色(自定义section布局)
- 设置UITableView Section的背景颜色和字体颜色
- 设置UITableView Section的背景颜色和字体颜色
- 设置UITableView Section的背景颜色和字体颜色 ----------自
- [iOS UItableView 自定义Section] 自定义Section 修改title样式
- 自定义UITableView的Section 的 title 的字体 和颜色
- ios 设置UITableView 选中行cell的背景颜色(自定义选中的背景颜色)
- UITableView自定义Section
- ios 修改UITableView的section之间的距离
- 如何修改UITableView中SectionTitle的背景色
- 自定义UITableView的Section的title的样式
- 修改UITableView背景图片
- UITableView自定义Section
- 自定义UITableView的Section的title的样式
- iOS中webView的字体大小/颜色 以及背景颜色修改
- iOSwebView修改字体大小字体颜色背景颜色
- AutoCompleteTextView控件自定义下拉框背景,点击效果,字体显示效果,匹配条件等效果
- android 修改窗体标题的字体式样和背景图(自定义标题栏)