2017-05-29 7 views
0

空のテーブルビューのバックグラウンドビューの内側にラベルを設定しています。これは、テーブルビューの中央にラベルを配置しています。UITableViewバックグラウンドビューのフレームを調整しますか?

私は少しそのラベルを上に移動したいのですが、それは、テーブルビューの上部付近しかし、以下のコードが動作していないのです。ただで\nを追加することにより、

UILabel *messageLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 20)]; 

messageLbl.text = @"NO REGISTRATIONS FOUND"; 
messageLbl.font = [UIFont fontWithName:@"Sansation-Bold" size:20.0f]; 
messageLbl.textColor = [UIColor lightGrayColor]; 
messageLbl.textAlignment = NSTextAlignmentCenter; 
[messageLbl sizeToFit]; 

//set back to label view 
self.tableView.backgroundView = messageLbl; 
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
self.tableView.backgroundView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 100); 
+0

tableLoveの代わりにtableLeaderViewにmessageLblを追加すると、TableViewのヘッダーとして使用されます。これはNavigationBarのすぐ下にあります。 –

+0

私はそのラベルを少し上に移動したいので、それはテーブルビューの一番上にあります。それは混乱する線です。あなたはちょうどそのラベルを上に近づけたい、それはちょっとではありません:) –

答えて

3

に追加することを忘れないでください。 tableHeaderViewへのごmessageLbl

UILabel *messageLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 50)]; 

messageLbl.text = @"\n\n NO REGISTRATIONS FOUND"; 
messageLbl.font = [UIFont fontWithName:@"Sansation-Bold" size:20.0f]; 
messageLbl.textColor = [UIColor lightGrayColor]; 
messageLbl.textAlignment = NSTextAlignmentCenter; 
messageLbl.numberOfLines = 0; 

[messageLbl sizeToFit]; 

//set back to label view 
self.tableView.tableHeaderView = messageLbl; 

enter image description here

+0

これは私が行ったことですが、うまくいきました –

+0

@AdamGハッピーコーディング:-) –

1

クイックソリューションですテキストの終わりと行の番号を0に設定します。この

messageLbl.numberOfLines = 0; 
messageLbl.text = @"NO REGISTRATIONS FOUND\n\n\n\n"; 
0

が は、いくつかのY軸の高さを設定することで、それを試してみてくださいあなたがナビゲーションバーの後ろにY軸を隠れていたように見えてみ&サブビュー別の簡単な解決策を追加することです

UILabel *messageLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.tableView.bounds.size.width, 20)]; 
messageLbl.text = @"NO REGISTRATIONS FOUND"; 
messageLbl.font = [UIFont fontWithName:@"Sansation-Bold" size:20.0f]; 
messageLbl.textColor = [UIColor lightGrayColor]; 
messageLbl.textAlignment = NSTextAlignmentCenter; 
[messageLbl sizeToFit]; 

//set back to label view 
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
[self.view addSubview: messageLbl]; 
関連する問題