2012-04-16 13 views
0

私は現在自分のカスタムセクションヘッダーを作成していますが、コードを使用してテキストを編集することはありません。カスタムヘッダーを作成するために使用している新しいメソッドは、示さenter image description here私は白にテキストを変更し、少し大胆なこととも白の背景を透明にしたいセクションヘッダーをカスタマイズするuilabel背景とテキスト

の下..

これは私がこの

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)]; 
    [headerView setBackgroundColor:[UIColor grayColor]]; 

    // Add the label 
    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.5, 20, 20)]; 

    // do whatever headerLabel configuration you want here 


    headerLabel.text = [self tableView:tableView titleForHeaderInSection:section]; 
    [headerView addSubview:headerLabel]; 

    // Return the headerView 
    return headerView; 
} 

を行うために使用していたコードです私はtを試した彼の

[headerLabel.backgroundColor:[UIColor clearColor]]; 

などが、そのは:(

答えて

5

を働いていない私は白にテキストを変更したいと思います...

UILabelのの、textColorプロパティがここにあなたの友達です。

そして、少し大胆な...

問題ありません! headerLabel.font = [UIFont boldSystemFontOfSize:mySize];

そして、白い背景を透明にします。

Whoa、whoa、これは、これまでに見られた最悪のセッター構文​​iveです。私の主人、myLabel.backgroundColorはゲッター、変更されています

[headerLabel.backgroundColor:[UIColor clearColor]]; 

へ:

[headerLabel setBackgroundColor:[UIColor clearColor]]; 

ラッキーあなたのためには、あなたの構文を使用すると、ちょうどである、nilにメッセージを送っているだろうラベルの背景色を白にデフォルト設定します。

+1

'headerLabel.backgroundColor = [UICに入れますolor clearColor]; 'もうまくいくはずです;) – Costique

+0

@Costique、mon dieu!何もゲッターを設定していません。 – CodaFi

+0

@CodaFi +1あなたが面白いので、答えを与えることでポイントブランク – Charan

2

次のコードを使用...

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

UILabel *headername = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, 270, 34)]; 
headername.backgroundColor = [UIColor clearColor]; 
headername.textColor = [UIColor blackColor]; 
if(section == 0) 
{ 
    headername.text = @"Name that u wish"; 
} 

else 
{ 
    headername.text = @"Name that u wish"; 
} 
UIView *headerView = [[UIView alloc] init]; 
UIImageView *tempimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 300,34)]; 
tempimage.image = [UIImage imageNamed:@"whitebackground.png"]; 

[headerView addSubview:tempimage]; 
[headerView addSubview:headername]; 

return headerView; 
} 

希望は、これはあなたが...

0

は、私が行っているすべては、以下れるような表でカスタマイズされたヘッダを取得するために寒さを助ける、それが正常に動作しています私

UIView *containerView = 
    [[[UIView alloc] 
     initWithFrame:CGRectMake(0, 0, 300, 60)] 
    autorelease]; 
UILabel *headerLabel = 
    [[[UILabel alloc] 
     initWithFrame:CGRectMake(10, 20, 300, 40)] 
    autorelease]; 
headerLabel.text = NSLocalizedString(@"Header for the table", @""); 
headerLabel.textColor = [UIColor whiteColor]; 
headerLabel.shadowColor = [UIColor blackColor]; 
headerLabel.shadowOffset = CGSizeMake(0, 1); 
headerLabel.font = [UIFont boldSystemFontOfSize:22]; 
headerLabel.backgroundColor = [UIColor clearColor]; 
[containerView addSubview:headerLabel]; 
self.tableView.tableHeaderView = containerView; 

のために私はちょうどviewDidLoad:方法

関連する問題