Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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
Iphone UILabel背景色_Iphone_Objective C - Fatal编程技术网

Iphone UILabel背景色

Iphone UILabel背景色,iphone,objective-c,Iphone,Objective C,我正试图用这段代码更改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;

我正试图用这段代码更改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; 
}
但是什么也没发生。

你能做到这一点吗:

- (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]; 
}

我总是这样做

m_ShopAddress.backgroundColor=[UIColor红色]

当我想改变阿尔法的时候


m_ShopAddress.alpha=0.0f

alpha值为0表示它是完全透明的。这可能就是为什么什么都没有发生(不管你是什么意思)

我不会访问图层的背景色,而是直接访问UILabel的背景色。

这将对您有所帮助

UILable *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,20,50,200)];
lbl.backgroundColor = [UIColor redColor];

如果使用的是情节提要,请检查情节提要中的视图背景是否有颜色。视图背景色覆盖了我的图层颜色。我将情节提要中视图的背景色更改为默认,这为我修复了它

所以我有了密码:

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的视图背景更改为默认值,图层颜色就会生效