2017-02-23 26 views
1

我有一個UITableView裏面有2個文本標籤。 我想將它們移動一點。UITableView填充文本和細節文本標籤(ios,xamarin)

我發現了整個細胞高度的屬性,但那不是一個即時通訊尋找。

哪個屬性可以幫助我?

這裏是代碼:

using System; 
using UIKit; 
using System.Collections.Generic; 

namespace iOSInputOutput 
{ 
    public class TableSource : UITableViewSource 
    { 

     List<string> gameNamesList; 
     List<string> gameIdsList; 

     string cellIdentifier = "TableCell"; 

     public TableSource(List<string> games, List<string> ids) 
     { 
      gameNamesList = games; 
      gameIdsList = ids; 
     } 

     public override nint RowsInSection(UITableView tableview, nint section) 
     { 
      return gameIdsList.Count; 
     } 

     public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath) 
     { 
      UITableViewCell cell = tableView.DequeueReusableCell(cellIdentifier); 
      //recucle cells that away from vision on screen 

      if (cell == null) 
       cell = new UITableViewCell(UITableViewCellStyle.Subtitle, cellIdentifier); 
      cell.TextLabel.Text = gameNamesList[indexPath.Row]; 


      cell.DetailTextLabel.Text = gameIdsList[indexPath.Row]; 

      //tableView.RowHeight = (nfloat) 124.0; 

      return cell; 
     } 
    } 
} 

回答

0

你需要你的願望裏面創建一個自定義的UITableViewCell和地方的標籤,不要試圖操縱蘋果的默認的UITableViewCell ...

剛子類的UITableViewCell

class CustomCell: UITableViewCell { 

let titleLabel: UILabel = { 
    let myVar = UILabel() 
    myVar.font = UIFont.systemFont(ofSize: 20) 
    return myVar 
}() 

let detailLabel: UILabel = { 
    let myVar = UILabel() 
    myVar.font = UIFont.systemFont(ofSize: 20) 
    return myVar 
}() 

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
    super.init(style: style, reuseIdentifier: reuseIdentifier) 
    self.contentView.addSubview(titleLabel) 
    self.contentView.addSubview(detalLabel) 
    self.setUp() 
} 

required init?(coder aDecoder: NSCoder) { 
    fatalError("init(coder:) has not been implemented") 
} 

func setUp() { 

    // here you do what you want with your labels (position them as you like) 

} 
} 
+0

非常感謝,很難得到任何答案的xamarin在這裏。 似乎是非常罕見的平臺或idk爲什麼會發生 – Vadim

+0

因爲每個人都在使用Xcode我想 – user3466447

+0

btw如何在setUp()中移動它們? – Vadim

相關問題