小编Nun*_*ira的帖子

iOS在哪里放置自定义单元格设计?awakeFromNib或cellForRowAtIndexPath?

所以,基本上我用笔尖制作了一个自定义单元格,希望我应用一些自定义设计,比如颜色和阴影.

我找到了两种应用样式的方法:

awakeFromNib():

override func awakeFromNib() {
    super.awakeFromNib()

    //Container Card Style
    self.container.layer.cornerRadius = 3
    self.container.setDropShadow(UIColor.blackColor(), opacity: 0.20, xOffset: 1.5, yOffset: 2.0, radius: 1.8)

    //Rounded thumbnail
    self.thumb_image.setRoundedShape()
    self.thumb_image.backgroundColor = UIColor.customGreyTableBackground()

    //Cell
    self.backgroundColor = UIColor.customGreyTableBackground()
    self.selectionStyle = .None
}
Run Code Online (Sandbox Code Playgroud)

cellForRowAtIndexPath :(在tableView中希望显示单元格)

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    //get cell type
    let cell = tableView.dequeueReusableCellWithIdentifier("searchResultCell", forIndexPath: indexPath) as! SearchResultCell

    //Container Card Style
    cell.container.layer.cornerRadius = 3
    cell.container.setDropShadow(UIColor.blackColor(), opacity: 0.20, xOffset: 1.5, yOffset: 2.0, radius: 1.8)

    //Rounded thumbnail
    cell.thumb_image.setRoundedShape()
    cell.thumb_image.backgroundColor = UIColor.customGreyTableBackground() …
Run Code Online (Sandbox Code Playgroud)

performance uitableview custom-cell ios swift

3
推荐指数
1
解决办法
2848
查看次数

标签 统计

custom-cell ×1

ios ×1

performance ×1

swift ×1

uitableview ×1