在此先感谢您的帮助。
我在主视图 Controller 中有一个 UITableView。在原型(prototype)单元格中,我有一个 UIImageview。在下面的代码中,一切正常,直到我添加 5 行以应用圆形蒙版和边框。一旦我这样做,除非我滚动单元格,否则图像将不会加载。然而, mask 和边框确实得到了完美的应用。当它起作用时会很棒......但在那之前。
当然,这以前见过。我是一个 swift/objective-C 新手。
正在为此快速工作。
下面的代码;
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("mixerCell", forIndexPath: indexPath) as! MixerTableViewCell
// set label background color to clear
cell.textLabel?.backgroundColor = UIColor.clearColor()
// set highlight selection to none
cell.selectionStyle = .None
// set image for cell
let imageView = cell.viewWithTag(1) as! UIImageView
// put circular mask and border. This is the problem code that causes initial load of the tableview images to show up blank.
imageView.layer.cornerRadius = imageView.frame.size.width / 2;
imageView.clipsToBounds = true;
let color1 = UIColor(white: 1.0, alpha: 0.5).CGColor as CGColorRef
imageView.layer.borderWidth = 2;
imageView.layer.borderColor = color1
// assign image
imageView.image = UIImage(named: mixerSounds[indexPath.row])
return cell
}
最佳答案
您的代码非常适合我。我在这里使用 Xcode-7。我认为您使用的是 Xcode-6.3 或更低版本。只需将它升级到 Xcode- 7。如果您使用的是相同的,那么只需检查您的 heightforRowAtIndexpath 或其他代表应该有一些问题。 谢谢
关于ios - 当圆形蒙版应用于 ImageView 时,UIImageView 中的图像不显示在 UITableView 中,除非滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083071/