我是新的swift語言... 製作帶圖片的簡單表格,並希望在單元格內設置圖像視圖的角半徑。ios在表格視圖單元格圖像中出現故障
代碼: -
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)!
cell.textLabel?.text = "Test"
cell.detailTextLabel?.text = "\(indexPath.row)"
if(cell.imageView != nil){
cell.imageView?.image = UIImage(named: "avatar")
cell.imageView?.layer.cornerRadius = cell.imageView!.frame.size.height/2
cell.imageView?.layer.masksToBounds = true
}
return cell
}
不知道我在做什麼錯,但是當我開始滾動表它正確設置圓角半徑不seted當表顯示...
編輯: - 與cell.imageView?.layer.cornerRadius = 20
得到很好的結果不知道它爲什麼與靜態值一起工作。
是否使用自動版式? – technerd
@technerd,是的,我正在使用它.. –
ImageView的大小是固定的還是取決於長寬比? – technerd