这是我所有细胞的样子。一些信息显示在单元格的右侧。而不是这种左侧有圆形半径图像而右侧有信息的设计。我希望我的单元格是一个图像,信息位于该图像的顶部。
这是我希望我的单元格具有的样式类型,没有图像之间的空间,我尝试通过删除信息标签并在单元格上使用水平堆栈 View 来进行此尝试。
但这就是细胞最终的样子。对于图像的半径,我没有以编程方式进行,而是通过 Identity Inspector 完成的
键路径
layer.cornerRadius
类型
编号
值
30
使图像变圆。除此之外,tableView 中没有涉及太多代码,大部分都是通过 Main.StoryBoard
完成的,下面我添加了一些代码来展示我如何配置单元格。关于如何完成此操作的任何提示或想法?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! RestaurantTableViewCell
//* Configure the cell...
cell.nameLabel.text = restaurants[indexPath.row].name
cell.thumbnailImageView.image = UIImage(named: restaurants[indexPath.row].image)
cell.locationLabel.text = restaurants[indexPath.row].location
cell.typeLabel.text = restaurants[indexPath.row].type
cell.accessoryType = restaurants[indexPath.row].isVisited ? .Checkmark : .None
return cell
}
最佳答案
如果您希望单元格显示图像,然后在该图像顶部显示文本,我建议您将图像设置为单元格背景 View (如果需要,将角变圆),然后填充标签和附件 View 正如您已经在做的那样。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let dictData : NSDictionary = arrayOfData.objectAtIndex(indexPath.row) as! NSDictionary
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = "THIS IS SOME TEXT"
if let image = dictData.objectForKey("Image"){
cell.backgroundColor = UIColor.clearColor()
let imageView = UIImageView(image: image as? UIImage)
imageView.layer.cornerRadius = 30.0
imageView.clipsToBounds = true
cell.backgroundView = imageView
}
return cell
}
这会让你在图片上看到文字:
关于ios - 如何将水平单元格重新设计为垂直单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34527159/