我可以轻松地使单元格完全透明(清晰的颜色),因此背景图像可以透过tableview和tableview单元格。
然而,我真正想要的是50%透明的细胞 - 即背景图像闪耀。 。 ......我想要完成的是不可能的?我已经在设置背景颜色时使用的颜色定义了alpha / opacity,但它似乎被忽略了(其余的颜色是正确的)
这是我的代码(最初从另一种语言/工具移植)
class ViewControllerCatalog: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var outletCatalog: UITableView!
override func viewDidLoad() {
super.viewDidLoad();
self.view.backgroundColor = UIColor(patternImage: FBackgroundImage.Content!);
outletCatalog.delegate = self;
outletCatalog.dataSource = self;
outletCatalog.backgroundColor = UIColor.clearColor();
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated);
// ... load data
outletCatalog.reloadData();
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell? = nil;
cell = tableView.dequeueReusableCellWithIdentifier("basic", forIndexPath: indexPath);
let idx: Int = indexPath.row;
// ... set other stuff
cell!.backgroundColor = Int64_To_UIColor(FCatalogArr.data_array![idx].background_color_int);
cell!.contentView.backgroundColor = Int64_To_UIColor(FCatalogArr.data_array![idx].background_color_int);
cell!.opaque = false;
}
// included here in full details - basicly I get colors as 4byte ints (although in int64) with alpha and rgb
func Int64_To_UIColor(AColor: Int64) -> UIColor {
//var StrDebug: String = "";
//StrDebug = String(format: "%2X", AColor);
var AI64: Int64 = AColor >> 24;
var RI64: Int64 = AColor >> 16;
var GI64: Int64 = AColor >> 08;
var BI64: Int64 = AColor >> 00;
AI64 = AI64 & 0xff;
//StrDebug = String(format: "%2X", AI64);
RI64 = RI64 & 0xff;
//StrDebug = String(format: "%2X", RI64);
GI64 = GI64 & 0xff;
//StrDebug = String(format: "%2X", GI64);
BI64 = BI64 & 0xff;
//StrDebug = String(format: "%2X", BI64);
let AF: CGFloat = CGFloat(AI64) / 255;
let RF: CGFloat = CGFloat(RI64) / 255;
let GF: CGFloat = CGFloat(GI64) / 255;
let BF: CGFloat = CGFloat(BI64) / 255;
let res: UIColor = UIColor(red: RF, green: GF, blue: BF, alpha: AF);
return res;
}
}
哪里
是的,我正在使用storyboard,但我尝试在代码中设置值,因为它更容易检查和调试并发布到SO。我更喜欢在使用代码时至少也工作的解决方案,因为我在运行时从配置和数据文件加载内容和样式。