gpt4 book ai didi

ios - Alpha 在 UITableViewCell 中不起作用

转载 作者:行者123 更新时间:2023-12-02 08:16:45 25 4
gpt4 key购买 nike

我正在继续开发针对 iPad 的 iOS 应用程序。和asked a question今天早上在网站上我得到了我的问题的正确答案。但由于某种原因,Alpha 无法在我的表格单元格中工作。

这是我的 View 与 TableView 的关系:

enter image description here

这是我的 Swift 代码:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

let data:[String] = ["Row 0","Row 1", "Row 2","Row 3","Row 4","Row 5","Row 6"]

@IBOutlet var tableView: UITableView!
var rowSelected:Int! = nil

override func viewDidLoad() {
super.viewDidLoad()
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:Cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! Cell
if rowSelected != nil {
if rowSelected > indexPath.row {
cell.alpha = 0.7
} else if rowSelected == indexPath.row {
cell.alpha = 1.0
} else {
cell.alpha = 0.3
}
}

cell.labelText.text = self.data[indexPath.row]

return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.rowSelected = indexPath.row

tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
}

当我选择一行时,没有任何反应,而 Alpha 则没有。在此示例中,我直接在单元格中应用了 Alpha(我禁用了单元格中的不透明选项 - 单元格不是不透明的)。 在原始应用程序中,我有 2 个标签、2 个按钮和一张图片。为了更加实用,需要在Cell中直接使用Alpha。

有人可以帮助我吗?

最佳答案

我知道这是一个旧线程。但我只想在这里留下我的建议,如果有人觉得有用的话。您可以将 alpha 应用于 UITableViewCell 的内容 View ,这对我有用。

cell.contentView.alpha = 0.3

关于ios - Alpha 在 UITableViewCell 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34726485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com