针对于iPhone的降频,苹果电池降频公司给出现在便宜买电池的方案只是解决一时用户对苹果电池降频的抵触,便宜买电池

7082人阅读
iphone开发学习和总结(280)
&有时候我们可以会嫌弃系统的section 的 title 的字体 和颜色 ,不美观,影响整个app 的 搭配。
上面的整体效果很差,那我们就要 自定义&UITableView的Section 的 title 的字体 和颜色 。
&用到自定义的时候可能比较多,下面是具体的方法:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0)
return @&简介&;
return @&&;
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 8, 320, 20);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(-1.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:20];
label.text = sectionT
UIView *view = [[UIView alloc] init];
[view addSubview:label];
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
if(section == 0)
return @& &;
return @&Copyright& JustinJing All Rights Reserved.&;
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
NSString *sectionTitle = [self tableView:tableView titleForFooterInSection:section];
if (sectionTitle == nil) {
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 8, 320, 20);
label.lineBreakMode=NSLineBreakByWordW
label.numberOfLines=0;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(-1.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:11];
label.text = sectionT
UIView *view = [[UIView alloc] init];
[view addSubview:label];
主要是设置section 的&viewForFooterInSection 和&viewForHeaderInSection 这样就可以自定义了。
修改后的效果是:
注意:示例代码没有release ,是因为我用了ARC,如果没有用ARC ,请注意Release
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1527626次
积分:14708
积分:14708
排名:第715名
原创:145篇
转载:191篇
评论:435条
(1)(3)(3)(2)(3)(1)(1)(2)(3)(3)(1)(6)(7)(11)(3)(4)(7)(4)(2)(2)(5)(3)(1)(2)(4)(1)(7)(2)(9)(14)(21)(32)(15)(13)(4)(6)(7)(6)(10)(20)(5)(13)(3)(1)(7)(3)(2)(13)(42)[分享]IOS开发 - 怎样在UITableView里修改section header的颜色_ios_ThinkSAAS
[分享]IOS开发 - 怎样在UITableView里修改section header的颜色
[分享]IOS开发 - 怎样在UITableView里修改section header的颜色
内容来源: 网络
1.希望这个从UITableViewDelegate协议里得到的方法可以对你有所帮助:
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
if (section == integerRepresentingYourSectionOfInterest)
[headerView setBackgroundColor:[UIColor redColor]];
[headerView setBackgroundColor:[UIColor clearColor]];
return headerV
使用任何你喜欢UIColor代替[UIColor redColor]。你可能还希望调整headerView的尺寸。
2.这是改变文本颜色的方法:
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 18)] autorelease];
label.text = @"Section Header Text Here";
label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75];
label.backgroundColor = [UIColor clearColor];
[headerView addSubview:label];
3.不要忘记从委托添加这段代码,否则在某些情况下视图将被切断或者出现在table后面,相对于视图/标签的高度。
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
return 30;
4.如果你想自定义header颜色,可以这样做:
[[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];
这个方法在iOS 6.0.以上都很好用。
5.这是在标题视图添加图片的方法:
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
UIImageView *headerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top-gery-bar.png"]] autorelease];
headerImage.frame = CGRectMake(0, 0, tableView.bounds.size.width, 30);
[headerView addSubview:headerImage];
return headerV
6.如果你不想建立自定义视图,你也可以这样改变颜色:
-(void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if ([view isKindOfClass: [UITableViewHeaderFooterView class]]) {
UITableViewHeaderFooterView* castView = (UITableViewHeaderFooterView*)
UIView* content = castView.contentV
UIColor* color = [UIColor colorWithWhite:0.85 alpha:1.]; // substitute your color here
content.backgroundColor =
7.这个方法不涉及定义和创建自定义视图。在iOS 6以上,你可以通过以下方法轻松改变背景色和文本色:
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
// Background color
view.tintColor = [UIColor blackColor];
// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)
[header.textLabel setTextColor:[UIColor whiteColor]];
// Another way to set the background color
// Note: does not preserve gradient effect of original header
// header.contentView.backgroundColor = [UIColor blackColor];
注:通过UITableViewHeaderFooterView设置背景色的方法已经被废弃了。请用contentView.backgroundColor代替。
分享来源:
PHP开发框架
开发工具/编程工具
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
让ThinkSAAS更好,把建议拿来。
开发客服微信主题 : 如何修改tableview的section title字体和颜色?
级别: 精灵王
发帖: 1297
可可豆: 3238 CB
威望: 3282 点
在线时间: 1475(时)
发自: Web Page
如何修改tableview的section title字体和颜色? &&&
我使用viewForHeaderInSection,倒是实现了自定义功能,但是在每个section的底部会有高度不等的空隙,求大神告诉我这可能是哪方面的问题呢?
级别: 精灵王
UID: 113399
发帖: 3620
可可豆: 5708 CB
威望: 6227 点
在线时间: 2595(时)
发自: Web Page
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle=[self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle==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=sectionT
// 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 sectionV
试试这样子是否可行?
级别: 精灵王
发帖: 1297
可可豆: 3238 CB
威望: 3282 点
在线时间: 1475(时)
发自: Web Page
虽然直接用不行,但是收老兄的启发,我找到原因了,谢啦~~~
级别: 精灵王
UID: 113399
发帖: 3620
可可豆: 5708 CB
威望: 6227 点
在线时间: 2595(时)
发自: Web Page
不客气 最后是怎么解决的?
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版

我要回帖

更多关于 苹果手机降频 的文章

 

随机推荐