2015-10-16 50 views
1

Little Blur inside the selected part in red從視圖

卸下模糊的部分我有梯度創造了這個觀點,但恰好是模糊的部分來了,我完全無能如何刪除它。

這裏是我的代碼:

NSArray *grandientColor = [NSArray arrayWithObjects: 
          (id) [[UIColor colorWithRed:1 green:1 blue:0.79 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:1 green:0.93 blue:0.61 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:1 green:0.85 blue:0.43 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:1 green:0.7 blue:0.25 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:1 green:0.55 blue:0.18 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:1 green:0.3 blue:0.1 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:0.9 green:0.08 blue:0.04 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:0.75 green:0 blue:0.13 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:0.51 green:0 blue:0.14 alpha:1] CGColor], 
          (id) [[UIColor colorWithRed:0.29 green:0 blue:0.08 alpha:1] CGColor],nil 
          ]; 

UIView *viewGradient = [[UIView alloc] initWithFrame:CGRectMake(15.0f, 50.0f, 126.0f, 25.0f)]; 

viewGradient.layer.cornerRadius = 5; 
viewGradient.layer.masksToBounds = YES; 
viewGradient.layer.borderColor = [UIColor blackColor].CGColor; 
viewGradient.layer.borderWidth = 2.0f; 

CAGradientLayer *maskLayer = [CAGradientLayer layer]; 
maskLayer.opacity = 0.8; 
maskLayer.colors = grandientColor; 

// Hoizontal - commenting these two lines will make the gradient veritcal 
maskLayer.startPoint = CGPointMake(0.0, 0.5); 
maskLayer.endPoint = CGPointMake(1.0, 0.5); 

maskLayer.bounds = viewGradient.bounds; 
maskLayer.anchorPoint = CGPointZero; 
[viewGradient.layer addSublayer:maskLayer]; 
[legendView addSubview:viewGradient]; 

請幫我出這一點。

謝謝提前。

回答

1

這實際上是發生在兩側,但是這是因爲漸變的顏色較淺的左側更明顯。它發生的原因是因爲圓角上的抗鋸齒文物;邊框繪製在漸變的頂部,所以當添加部分繪製的邊框像素時,漸變類型會在錯誤的一側的邊框後面泄漏。

修復它在你的情況下,最簡單的方法是使梯度層比其父一個略小。因此,與其相匹配的界限,你可以這樣做:

// maskLayer.bounds = viewGradient.bounds; 
maskLayer.anchorPoint = CGPointZero; 
maskLayer.frame = CGRectInset(viewGradient.bounds, 1, 1); 
maskLayer.cornerRadius = 4; 

你還需要招行設置上面,你設定的框架anchorPoint,並應用圓角半徑,如在上面的代碼。

這將產生預期的效果:

Desired effect

如果我們的邊界部分透明的,你可以看到發生了什麼:從羅伯特

enter image description here

+0

它的工作非常感謝。 :-) –

0

也許你在談論cornerRadius不模糊? 你到底想說什麼? 你不透明度0.8它給透明 刪除此:

viewGradient.layer.cornerRadius = 5; // rounds your view 
maskLayer.opacity = 0.8; // make your view transparent 
+0

答案的工作很適合我,但謝謝你的努力。 :-) –