Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 加载具有与其UICollectionView不同alpha值的UICollectionViewCell_Ios_Iphone_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios 加载具有与其UICollectionView不同alpha值的UICollectionViewCell

Ios 加载具有与其UICollectionView不同alpha值的UICollectionViewCell,ios,iphone,swift,uicollectionview,uicollectionviewcell,Ios,Iphone,Swift,Uicollectionview,Uicollectionviewcell,我无法为我的UICollectionViewCell指定与拥有它们的UICollectionView不同的alpha。我看过其他一些类似的帖子,但没有一篇适合我。我有一个带有UICollectionView的.xib文件,其中alpha设置为0.9,其中的单元格从另一个.xib文件加载,alpha设置为1.0。无论我做了什么尝试,UICollectionView的alpha优先。这些尝试包括: func collectionView(collectionView: UICollectionVie

我无法为我的
UICollectionViewCell
指定与拥有它们的
UICollectionView
不同的alpha。我看过其他一些类似的帖子,但没有一篇适合我。我有一个带有
UICollectionView
的.xib文件,其中alpha设置为0.9,其中的单元格从另一个.xib文件加载,alpha设置为1.0。无论我做了什么尝试,
UICollectionView
的alpha优先。这些尝试包括:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! Cell

// Here is the first attempt
    cell.alpha = 1.0
    cell.contentView.alpha = 1.0

// Here is the second attempt
    let attribute = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
    attribute.alpha = 1.0
    cell.applyLayoutAttributes(attribute)

    cell.setNeedsDisplay()
    return cell
我希望单元格加载时没有透明度,但我希望包含它们的集合视图稍微透明。每个单元格上都加载了一个完全不透明的唯一图像

编辑1:我尝试将
UICollectionView
backgroundColor
设置为1.0 alpha清除,然后在我的
viewDidLoad()
方法中给它一个自定义
backgroundView
。我有一个集合视图的
@IBOutlet
,用于设置以下内容:

@IBOutlet weak var collectionView: UICollectionView!

// MARK: -View Lifecycle
override func viewDidLoad() {
    super.viewDidLoad()

    collectionView.delegate = self
    collectionView.dataSource = self

    let background = UIView(frame: collectionView.bounds)
    background.backgroundColor = UIColor(red: 26/255.0, green: 26/255.0, blue: 26/255.0, alpha: 0.97)
    collectionView.backgroundView = background

    collectionView.registerNib(UINib(nibName: "Cell", bundle: nil), forCellWithReuseIdentifier: "Cell")

}

这确实有效。

您不能使用alpha创建父视图!=1和alpa=1的孩子,他们不会像预期的那样工作


通常我所做的是使用一个辅助视图(与集合视图相同的框架),父视图(您的集合视图)的同级视图,alpha设置为X值。将集合视图背景颜色设置为clearColor。

是否希望集合视图的alpha值为0.9,而集合视图单元格的alpha值为1.0?是的!collectionView的alpha值为0.9,它为单元格提供了相同的alpha值。请尝试将背景视图设置为collection视图,然后更改其alpha值。希望这将有助于请查看我的编辑。恐怕我做得不对吧?