我已经做了样品为你关闭你的要求。看一看 https://github.com/RajanMaheshwari/CustomTableCell
我想用UITableView
来做这个。 我的方法将采取一个自定义单元格,并添加一个UIView与左,右,上下的一些限制。 此外,我将提供相同的背景色为UITableView
,UIView
这是上海华和单元格内容视图,也使UITableView
的separator
为None
和TableCell的选择为None
,这样的UI看起来像
接下来将每一个约束,使一个CustomC后并制作IBOutlets,我们将跳转到代码。
我会做所有的阴影,并在自定单元的awakeFromNib
方法
概述这将是我CustomTableViewCell
类
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var labelBackgroundView: UIView!
@IBOutlet weak var cellLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
labelBackgroundView.layer.borderWidth = 0.5
labelBackgroundView.layer.borderColor = UIColor.lightGrayColor().CGColor
labelBackgroundView.layer.shadowColor = UIColor.lightGrayColor().CGColor
labelBackgroundView.layer.shadowOpacity = 0.8
labelBackgroundView.layer.shadowRadius = 5.0
labelBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 2.0)
labelBackgroundView.layer.masksToBounds = false;
}
我有两个出口。
一个是您将在其中显示名称的标签。 其他是你想用一些轮廓和阴影显示的外部视图。
的视图控制器代码将是:
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
var array = [String]()
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
array = ["Wealth","Health","Esteem","Relationship"]
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomTableViewCell") as! CustomTableViewCell
cell.cellLabel.text = array[indexPath.row]
cell.labelBackgroundView.tag = indexPath.row
cell.labelBackgroundView.userInteractionEnabled = true
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(cellViewTapped))
cell.labelBackgroundView.addGestureRecognizer(tapGesture)
return cell
}
func cellViewTapped(sender:UITapGestureRecognizer) {
let view = sender.view
let index = view?.tag
print(index!)
}
}
在这里,我没有使用过的UITableViewDelegate
didSelectIndex
因为我只想在大纲LabelBackgroundView水龙头,而不是完整的细胞。
所以最终的结局是这样的
这是完美的!我近在咫尺......我在自定义单元格内的容器视图中使用了一个标签......我之前看到的所有内容都是在设计之上的白色空间......无论如何,这在我删除后为我工作我的整个故事板和课程,并从头开始!非常感谢! – Agustin
如果它适合您,请接受为蜱。谢谢 –
我的坏...我以前做过...做过! :) 再次感谢 – Agustin