use*_*707 0 colors tableviewcell swift
我已经检查了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
}
Run Code Online (Sandbox Code Playgroud)
然而,我的胜利和失败都出现在我的桌子中,颜色,图像和文字都像我想要的那样出现.
在旁注,有人可以教我如何选择婴儿蓝或婴儿红等颜色?默认的红色和蓝色对我的应用来说太强了:(
谢谢你的帮助!
默认单元格样式没有detailTextLabel.您需要使用.Value1或.Subtitle作为UITableViewCellStyle:
var cell = UITableViewCell(style: .Value1, reuseIdentifier: nil)
Run Code Online (Sandbox Code Playgroud)
您可以使用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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2720 次 |
| 最近记录: |