我使用UIView的扩展来定制UITableViewCell显示:
import UIKit
private var materialKey = false
private var _cornerRadius = 3.0
private var _borderWidth = 0.0
extension UIView{
@IBInspectable var borderWidth:Double{
get{
return _borderWidth
}
set{
_borderWidth = newValue
}
}
@IBInspectable var cornerRadius:Double{
get{
return _cornerRadius
}
set{
_cornerRadius = newValue
}
}
@IBInspectable var materialDesign:Bool{
get{
return materialKey
}
set{
materialKey = newValue
if materialKey{
self.layer.masksToBounds = false
self.layer.cornerRadius = CGFloat(_cornerRadius)
self.layer.shadowOpacity = 0.8
self.layer.shadowRadius = 5.0
self.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
self.layer.shadowColor = UIColor(red: 157/255, green: 157/255, blue: 157/255, alpha: 1.0).cgColor
}else{
layer.cornerRadius = 0
layer.shadowOpacity = 0
layer.shadowRadius = 0
layer.shadowColor = nil
}
}
}
但是,当我运行App(无论是真正的设备还是模拟器)时,它看起来像这样:
第一个Cell和另一个看起来不一样:( 谁能告诉我为什么???谢谢!