我拥有一部 iPhone 5 并且一直在上面测试应用程序,一切都在 iPhone 5 设备、iPhone 5 和 6 模拟器上运行,但是当我借用 iPhone 6 时,奇怪的灰线开始出现和消失(当我移动 iPhone 时,它们会移动并消失)在集合视图单元格周围,按钮(都在UIView
容器中)
我删除了所有内容,但它们仍然存在,我隐藏了单元格中的按钮,将所有背景和边框颜色清除;这些线有点像单元格的边界。
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch collectionView{
case collectionViewOne!:
return collectionViewOneRows
case collectionViewTwo!:
return collectionViewTwoRows
default: return 0
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
switch collectionView{
case collectionViewOne!:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell
cell.backgroundColor = UIColor.whiteColor()
cell.textLabel.text = "Hempel Product"
println(Int(indexPath.row))
cell.buttonView.tag = Int(indexPath.row)
cell.buttonView.setBackgroundImage(UIImage(named: "Hempel"), forState: UIControlState.Normal)
cell.buttonView.addTarget(self, action: Selector("Action:"), forControlEvents: UIControlEvents.TouchUpInside)
cell.layer.cornerRadius = 3
return cell
case collectionViewTwo!:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell1", forIndexPath: indexPath) as! CollectionViewCell
cell.backgroundColor = UIColor.whiteColor()
cell.textLabel.text = "Hempel Product1"
println(Int(indexPath.row))
cell.buttonView.tag = Int(indexPath.row)
cell.buttonView.setBackgroundImage(UIImage(named: "Hempel"), forState: UIControlState.Normal)
cell.buttonView.addTarget(self, action: Selector("Action1:"), forControlEvents: UIControlEvents.TouchUpInside)
cell.layer.cornerRadius = 3
return cell
default:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell
return cell
}
}
有没有人有这方面的经验?
class CollectionViewCell: UICollectionViewCell {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
var textLabel: UILabel = UILabel()
var buttonView: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
// problem sa iphone 6 crtice
contentView.backgroundColor = UIColor.clearColor()
contentView.layer.borderColor = UIColor.clearColor().CGColor
//
buttonView = UIButton.buttonWithType(UIButtonType.System) as! UIButton
buttonView.frame = CGRect(x: frame.width / 2 - frame.width * 0.3, y: 0, width: frame.size.width * 0.6, height: frame.size.height * 0.8)
contentView.addSubview(buttonView)
let textFrame = CGRect(x: 0, y: 90, width: frame.size.width, height: frame.size.height/3)
textLabel = UILabel(frame: textFrame)
textLabel.font = UIFont.systemFontOfSize(UIFont.smallSystemFontSize())
textLabel.textAlignment = .Center
contentView.addSubview(textLabel)
}
}