最佳答案
我试过不使用自定义单元格
。
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
}
}
输出
关于ios - 匹配设计的 UITableViewCell 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48473267/