2017-08-19 10 views
1

私のアカウントには、設定のApple IDページと同様に、アカウント情報をテーブルビューの最初のセクションの上に表示するアカウントページがあります。UITableViewの区切り文字を変更する

AppleIDPage

私の質問は、プロフィール写真の上に示されないセパレータが存在しないようにビューを構築する方法の周りに基づいています。または、情報がテーブルビュー内にあるように見えるが、セクション内には表示されないようにする。

セパレータを表示したり、表示したりするのは不可能か非常に難しいようです。

リンゴIDページの場合は、その画像、名前、電子メールがそれ自身のセクションまたはその下のセクションに含まれるセルですか?

次の画像は、トップセパレータが非表示にすることは困難ですが、私が得たものと最も近い画像です。質問の幅広い自然を

MyAttempt

謝罪は、しかし、私は目的が明確だと思うし、ソリューションに達すると私は、将来の視聴者のための質問は、より具体的になります。

ありがとうございました。

+0

私はDEFAを隠し、セパレーターのようにそれを置き、カスタムセルに 'UIView'を追加しています超分離器なので、隠す/表示する/色を付けるのは簡単です – JuicyFruit

答えて

0

感謝のDevとPGDev、私はstatic cellsのためによく働いた素敵な解決策を考え出すことができました。私はUITableViewCellのためにextensionを作った。最初の関数separator()

let separatorColour = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 0.5) 

extension UITableViewCell { 
    func separator(topInset: CGFloat, btmInset: CGFloat, showTop: Bool, showBtm: Bool) { 

     if showTop { 
      let topSeparator: UIView = UIView() 
      topSeparator.frame = CGRect(x: topInset, y: 0, width: frame.width, height: 0.5) 
      topSeparator.backgroundColor = separatorColour 
      addSubview(topSeparator) 
     } 

     if showBtm { 
      let btmSeparator: UIView = UIView() 
      btmSeparator.frame = CGRect(x: btmInset, y: frame.height - 0.5, width: frame.width, height: 0.5) 
      btmSeparator.backgroundColor = separatorColour 
      addSubview(btmSeparator) 
     } 
    } 

    func btnSeparator() { 

      let topSeparator: UIView = UIView() 
      topSeparator.frame = CGRect(x: 0, y: 0, width: frame.width, height: 0.5) 
      topSeparator.backgroundColor = separatorColour 
      addSubview(topSeparator) 

      let btmSeparator: UIView = UIView() 
      btmSeparator.frame = CGRect(x: 16, y: frame.height - 0.5, width: frame.width - 32, height: 0.5) 
      btmSeparator.backgroundColor = separatorColour 
      addSubview(btmSeparator) 
    } 
} 

あなたは単に上部と下部separatorのため、彼らが表示されているか否かのインセットを選択することができます。上の写真に示すname label、上部及び底部の両方separatorscellの場合

screenshot1screenshot2

TopCell だからが見え​​ます。しかし、セクション内に最初のcellとして表示されるはずであるため、上部のインセットと適切な下部のインセットがありません。それだけ有するemail labelcellの場合

MiddleCell 下部cellが上記底separatorseparatorを有するもの(挿入図とともに)見えます。 password labelcellについてBottomCell

、それだけ低いseparatorcellが上記底separatorを有するように見える(オフセットなし)を有しています。

SpecialCase btnSeparator()機能はちょうど私が両側に差し込またかっヘルプとサポートボタンの場合のためでした。

は今、このextensionを実装するために、私は、各cellに適切なextensionを与えることcellForRowAt関数内switch statementを使用し、これはそれがどのように見えるかです:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = super.tableView(tableView, cellForRowAt: indexPath) 
     let inset: CGFloat = 16   

     switch indexPath { 

     // First Section 
     case [0,1]: 
      cell.separator(topInset: 0, btmInset: inset, showTop: true, showBtm: true) 
     case [0,2]: 
      cell.separator(topInset: inset, btmInset: inset, showTop: false, showBtm: true) 
     case [0,3]: 
      cell.separator(topInset: inset, btmInset: 0, showTop: false, showBtm: true) 

     // Second Section 
     case [1,0]: 
      cell.separator(topInset: 0, btmInset: inset, showTop: true, showBtm: true) 
     case [1,1]: 
      cell.separator(topInset: inset, btmInset: inset, showTop: false, showBtm: true) 
     case [1,2]: 
      cell.separator(topInset: inset, btmInset: 0, showTop: false, showBtm: true) 

     // Third Section 
     case [2,0]: 
      cell.btnSeparator() 
     case [2,1]: 
      cell.separator(topInset: inset, btmInset: 0, showTop: false, showBtm: true) 
     case [2,3]: 
      cell.separator(topInset: 0, btmInset: 0, showTop: true, showBtm: true) 

     default: 
      print("default") 
     } 
     return cell 
    } 

Storyboardで誰にも負けないseparatorを設定してくださいまたは使用:

tableView.separatorStyle = UITableViewCellStyle.None

1

この

//を試してみてくださいこれは、すべての行の区切り文字

tableView.separatorStyle = UITableViewCellStyle.None 

//カスタム区切り文字

if indexPath.row != 0{ 
     var aView: UIView = UIView() 
     aView.frame = CGRect(x:0,y:44,width:300,height:1) 
     aView.backgroundColor = UIColor.redColor() 
     cell .addSubview(aView) 
} 
1

についてあなたはそのためにあなたのUITableViewCellcustom viewを使用する必要が非表示になります。

storyboardnoneからUITableViewSeparatorを設定します。

2.UITableViewCellUIViewというカスタムを作成します。

class TableCell: UITableViewCell 
{ 
    @IBOutlet weak var separatorView: UIView! 
} 

3.あなたの条件に応じてcellForRowAtseparatorViewbackgroundColorを設定します。

例:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
{ 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableCell 
    switch indexPath.row 
    { 
    case 0: 
     cell.backgroundColor = .red 
    case 1: 
     cell.backgroundColor = .green 
    case 2: 
     cell.backgroundColor = .blue 
    case 3: 
     cell.backgroundColor = .yellow 
    default: 
     cell.backgroundColor = .orange 
    } 
    return cell 
} 

スクリーンショット:

enter image description here

関連する問題