2016-12-21 3 views
0
func numberOfSections(in tableView: UITableView) -> Int { 

    return 1 
} 


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return leadername.count 

} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "leadCell") as! LeaderBoardTableViewCell 
    cell.leaderNameLbl.text = leadername[indexPath.row] 
    cell.areaLbl.text = areaName[indexPath.row] 
    cell.approvalLabel.text = approvalrate[indexPath.row] 
    cell.leaderImageView?.image = UIImage(named: leaderImage[indexPath.row]) 
    cell.backgroundColor = UIColor.white 

    //cell.contentView.backgroundColor = transparentColor 


      return cell 

} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


} 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

    return 85 
} 

私は多くのソリューションをチェックしましたが、どれも私のために働いていません。私はセルの高さ、テーブルビューの高さなどを変更しました。しかし、それは私のために働いていません。どうすればこれを達成できますか?助けてください。スワップアイオスの2つのカスタムテーブルビューセルの間にスペーシングを追加するには?

+0

私の意見では、あなたの問題の2つの方法があります:1.各UITableViewCellは1つのセクションに表示されるので、各セクションのスペースを処理できます。 2. UITableViewCellで、contentViewを小さく設定すると、セル間のスペースが表示されます。 – nynohu

+0

@nynohuどのようにコンテンツビューを小さく設定するのですか?あなたは私のコードでそれを行う方法を私に見せてもらえますか? – Rakesh

+0

ユーザインタフェースを使用する場合は、すべてのコンテンツをcontentViewのサブビューに追加できます。また、このサブビューの表示サイズを調整して表示することもできます。 – nynohu

答えて

1

これは2通りの方法で達成できます。

1)セルごとにセクションを追加し、セクション内にセクションビューを追加してクリアカラーで表示することで、2つのセルの間に空白が表示されるようにすることができます。

2)テーブルビューセルを適切な方法で設計することによって、2つのセルの間にスペースを入れることができます。第footerViewことで

: -

func numberOfSections(in tableView: UITableView) -> Int { 
    return 5 //yourCellArrayCount; 
} 
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 

let view = UIView(frame: CGRect (x:0, y: 0, width:10, height: 10)) 
    view.backgroundColor = UIColor.clear 
    return view 
} 

あなたはUI設計によって間隔を表示したい場合は、あなたの細胞containerviewとあなたの細胞containerview用に設定鮮明な色、あなたのビュー10pxのサイズを小さくします。

このイメージをチェックすると、より良いアイデアが得られます。 enter image description here 赤色は、セルの主なコンテナビューであり、透明にします。あなたのテーブルの

最終的な出力はこの enter image description here

新しい更新

変更をあなたのテーブルビューのメソッドを好きで、これを置きます。

func numberOfSections(in tableView: UITableView) -> Int { 
    return 3 
} 
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 20 
} 
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    let view = UIView(frame:CGRect (x: 0, y: 0, width: 320, height: 20)) as UIView 
    view.backgroundColor = UIColor.red 
    return view 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return 1 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

let cell = tableView.dequeueReusableCell(withIdentifier: "leadCell") as! LeaderBoardTableViewCell 
cell.leaderNameLbl.text = leadername[indexPath.row] 
cell.areaLbl.text = areaName[indexPath.row] 
cell.approvalLabel.text = approvalrate[indexPath.row] 
cell.leaderImageView?.image = UIImage(named: leaderImage[indexPath.row]) 
cell.backgroundColor = UIColor.white 

//cell.contentView.backgroundColor = transparentColor 


     return cell 

} 

これをチェックして、データ表示のロジックを変更します。私はこれをテストして、2つのセルの間に赤いスペースを表示します。いったん完了すると、赤をクリアカラーに変更することができます。

+0

変更はありません。それはそれと同じです。私はcontentviewの背景色を変更しました。 – Rakesh

+0

まず最初に1つのセル、例えば50 * 50サイズを取り、そのセルのコンテナビューを透明な色にして別のビューを作成し、サイズが(5,5,40,40)のtempViewとし、containerViewに配置しますあなたのすべてのコンテンツを配置する必要がありますtempViewとあなたのtempViewに応じて制約を設定します。あなたのheightForCellメソッドでは50を返します。何か問題があるかどうか教えてください。 – Pankaj

+0

変更はありません – Rakesh

関連する問題