2014-01-17 82 views
5

的自定義邊框我做的UIButton爲圓形的自定義邊框的子類:Tintcolor中的UIButton

- (void)drawRect:(CGRect)rect 
{ 
    [[self layer] setCornerRadius:CORNER_RADIUS]; 
    [[self layer] setMasksToBounds:YES]; 
    [[self layer] setBorderWidth:1]; 
    [[self layer] setBorderColor:self.tintColor.CGColor]; 
    [self.imageView setTintColor:self.tintColor]; 
} 

的問題是出現酥料餅時,自定義邊框不會有其他的控制與tintColor的相同的行爲:

enter image description here

enter image description here

我該如何處理呢?

非常感謝

回答

6

實現tintColorDidChange在你的UIButton子類。 iOS將按鈕的tintColor更改爲灰色,但該圖層的borderColor仍舊是舊的藍色。你必須自己改變borderColor,iOS沒有辦法知道邊框應該像你的色彩一樣着色。

- (void)tintColorDidChange { 
    [super tintColorDidChange]; 
    [self setNeedsDisplay]; 
} 

您使用setNeedsDisplay後,系統會調用drawRect:,這應該更新圖層顏色。

你很可能這個問題,以及:

- (void)tintColorDidChange { 
    [super tintColorDidChange]; 
    [[self layer] setBorderColor:self.tintColor.CGColor]; 
} 
+0

它的工作!謝謝 ;) – fabrizotus