ios - 匹配设计的 UITableViewCell 功能

标签 ios uitableview

是否可以使用 UITableViewCell 获取以下内容,而无需创建自定义 UITableViewCell

enter image description here

最佳答案

我试过不使用自定义单元格

var tableView = UITableView()



override func viewDidLoad() {
    super.viewDidLoad()

    tableView = UITableView(frame: self.view.bounds, style: UITableViewStyle.plain)
    tableView.dataSource = self
    tableView.delegate = self
    tableView.backgroundColor = UIColor.white
    tableView.tableFooterView = UIView()
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "myIdentifier")

    tableView.frame = CGRect(x:0 , y:64, width:self.view.bounds.width, height:self.view.bounds.height)//Optional for table size

    self.view.addSubview(tableView)
}


func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

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

    return 5
}

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


    let myCell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "myIdentifier")

    myCell.textLabel?.textColor = UIColor(red: 0, green: 137/255, blue: 197/255, alpha: 1.0)
    myCell.textLabel?.numberOfLines = 2
    myCell.textLabel?.font = UIFont.boldSystemFont(ofSize: 12)
    myCell.textLabel?.halfTextColorChange(fullText: "Claim Submission\n6/10/2016", changeText: "6/10/2016")

    myCell.detailTextLabel?.textColor = UIColor(red: 0, green: 137/255, blue: 197/255, alpha: 1.0)
    myCell.detailTextLabel?.numberOfLines = 2
    myCell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: 11) // (ofSize: 11)
    myCell.detailTextLabel?.halfTextColorChange(fullText: "$0.01\nBal:$999.99", changeText: "Bal:$999.99")


    return myCell
}


extension UILabel {
  func halfTextColorChange (fullText : String , changeText : String ) {
    let strNumber: NSString = fullText as NSString
    let range = (strNumber).range(of: changeText)
    let attribute = NSMutableAttributedString.init(string: fullText)
    attribute.addAttribute(NSForegroundColorAttributeName, value: UIColor.darkGray , range: range)
    attribute.addAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 9)], range: range)
    self.attributedText = attribute
  }
}

输出

enter image description here

关于ios - 匹配设计的 UITableViewCell 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48473267/

相关文章:

ios - 如何为 UITableViewController 的 View 设置委托(delegate)和数据源?

ios - TableViewCell 的几个问题

objective-c - 在 Storyboard 中创建独立 View 以编程方式使用

ios - 如何在 Localized.strings 中添加基本本地化文件

ios - 将文件添加到已打包的 .ipa 中

iOS Assistive Touch 用黑色补丁弄乱屏幕

ios - 每次向下滚动时如何在 UITableView 上居中显示加载 View ?

objective-c - UITableView 动画期间的用户交互

ios - 如何从 JSON 数据响应中获取 UIImage?

iOS 蓝牙 scanForPeripheralsWithServices 没有结果