2013-03-18 38 views
0

我想在位於自定義UITableViewCell中的UILabel文本後面添加漸變圖層。問題在於漸變隱藏了我標籤的文字。我已經訪問this鏈接,但它不適合我。所以我怎樣才能將它添加後面的文字層添加漸變隱藏UITableViewCell中的UILabel文本

我迄今所做的是:

CAGradientLayer *gradient = [CAGradientLayer layer]; 
    gradient.frame = CGRectMake(0, 0, buyPrice_port.frame.size.width, buyPrice_port.frame.size.height); 
    gradient.colors = [NSArray arrayWithObjects:(id)gainBackgroundColor1, (id)gainBackgroundColor2, nil]; 
    gradient.locations = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.00], [NSNumber numberWithFloat:0.70] , nil]; 
    [buyPrice_port.layer insertSublayer:gradient atIndex:0]; 
    buyPrice_port.textColor = [UIColor blackColor]; 
+0

你有什麼解決方案嗎? – 2017-08-05 16:02:29

+0

@YossiTsafar對不起,我不記得了。你可以使用[this](https://stackoverflow.com/a/4850506/437146)方法 – NightFury 2017-08-05 16:09:05

回答

0

你可以簡單地添加UILabel後視圖(即添加標籤爲梯度視圖的子視圖),並保持標籤透明。