ios - 文本和详细文本标签之间的 UITableView 填充(ios、xamarin)

标签 ios uitableview xamarin

我有一个 UITableView,里面有 2 个文本标签。 我想稍微移动一下。

我找到了整个单元格高度的属性,但这不是我要找的。

哪些属性可以帮助我?

代码如下:

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;
        }
    }
}

最佳答案

您需要创建一个自定义的 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)

 }
}  

关于ios - 文本和详细文本标签之间的 UITableView 填充(ios、xamarin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42421147/

相关文章:

android - 更改自定义 AutoCompleteTextView 的下划线颜色

ios - 是否允许在 UIWebView 上禁用滚动?

ios - Swift 3.0 与 2.2 源代码不兼容……我必须重建我的应用程序吗?

swift:使用 UIDatePicker 从动态单元格将值发送回 UITableViewController

ios - 向下滚动页面一次后显示表格 View 按钮

c# - 如何使用 visual studio 和 xamarin 关闭 android Activity

xamarin - Google Analytics 的用户代理字符串

ios - 如何将数据从 ViewModel 层传递到 View 层

ios - Apple 的 SwiftUI 教程代码在自制副本中不显示 View 内容

ios - TableView 委托(delegate) - Swift