我正在尝试使用此代码更改UILabel背景颜色
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
m_ShopName.text = m_CurrShop.m_Name;
m_ShopAddress.layer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0].CGColor;
}
但没有发生任何事情。
答案 0 :(得分:1)
你能做到这一点:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
m_ShopName.text = m_CurrShop.m_Name;
m_ShopAddress.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
}
答案 1 :(得分:1)
这会对你有所帮助
UILable *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,20,50,200)];
lbl.backgroundColor = [UIColor redColor];
答案 2 :(得分:0)
我总是做以下
m_ShopAddress.backgroundColor = [UIColor red];
当我想要更改alpha ...
时m_ShopAddress.alpha = 0.0f;
答案 3 :(得分:0)
alpha值为0表示完全透明。这可能就是为什么没有发生的事情(无论你的意思是什么)。
我不会直接访问图层的背景颜色,而是 UILabel 。
答案 4 :(得分:0)
如果您使用的是故事板,请检查故事板中是否有视图背景的颜色。视图背景颜色覆盖了我的图层颜色。我将故事板中视图的背景颜色更改为默认值,这为我修复了它。
所以我有了代码:
func select() -> Void {
imageViewBackgroundView.layer.backgroundColor = UIColor.black.cgColor
cellImageView.layer.backgroundColor = UIColor.black.cgColor
cellLabel.layer.backgroundColor = UIColor.black.cgColor
cellLabel.textColor = UIColor.white
}
cellLabel是未改变的视图背景。我曾经一次为故事板中的视图设置背景颜色。一旦我将cellLabel的视图背景更改为默认值,图层颜色就会生效。