我已经在stackOverFlow周围寻找了一个解决方案,但我的代码似乎仍然不起作用。我的detailTextLabel仍然没有出现:
想知道我做错了什么,这是我的代码
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()
// display our ranked data
cell.textLabel?.text = "\(championListInGame[indexPath.row])"
if let url = NSURL(string: "http://ddragon.leagueoflegends.com/cdn/img/champion/loading/\(championListInGame[indexPath.row])_0.jpg"){
if let urlData = NSData(contentsOfURL: url){
cell.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
cell.imageView?.image = UIImage(data: urlData)
}
}
if victory[indexPath.row] == true {
cell.backgroundColor = UIColor.blueColor()
cell.detailTextLabel?.text = " "+"victory!"
} else {
cell.backgroundColor = UIColor.redColor()
cell.detailTextLabel?.text = " "+"defeat!"
}
return cell
}我的胜利和失败都出现在我的桌子上,然而,颜色、图像和文本都以我想要的方式出现。
另外,有人能教我如何选择像婴儿蓝色或婴儿红色这样的颜色吗?对于我的应用程序来说,默认的红色和蓝色太强了:
谢谢你们的帮助!
发布于 2015-08-26 01:17:35
默认的单元格样式没有detailTextLabel。您需要使用.Value1或.Subtitle作为UITableViewCellStyle
var cell = UITableViewCell(style: .Value1, reuseIdentifier: nil)您可以使用UIColor:red:green:blue:alpha:构造函数来定制颜色。所有的值都从0.0到1.0不等。你可以在网上寻找颜色。如果指定的值在0到255个范围内,则可以通过将值除以255.0来转换它们:
let babyRed = UIColor(red: 1.0, green: 0.6, blue: 0.6, alpha: 1.0)
let babyBlue = UIColor(red:128.0/255.0, green: 178.0/255.0, blue: 255.0/255.0, alpha: 1.0)https://stackoverflow.com/questions/32216349
复制相似问题