0
我試圖做一個自定義的UIButton類,除,繪製按鈕的背景時,添加它作爲使用insertSubLayer後面的子層:方法,它仍會出現盈方的UIButton的爲textLabel。CAGradientLayer出現上述
我的代碼貼在下面,任何幫助將不勝感激。
CALayer *layer = self.layer;
layer.cornerRadius = 3.0f;
layer.masksToBounds = YES;
layer.borderWidth = 1.0f;
layer.borderColor = [UIColor colorWithWhite:0.5f alpha:0.5f].CGColor;
self.titleLabel.textColor = [UIColor greenColor];
//layer.backgroundColor = [UIColor greenColor].CGColor;
bgColor = [CAGradientLayer layer];
bgColor.frame = self.layer.bounds;
self.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
bgColor.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithWhite:0.97f alpha:1].CGColor,
(id)[UIColor colorWithWhite:0.87f alpha:1].CGColor,
nil];
bgColor.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:1],
nil];
[self.layer addSublayer:bgColor];
[self.layer insertSublayer:bgColor below:layer];
這是哪裏的代碼在你的按鈕類? – jrturton 2012-07-31 11:00:08
它在InitWithFrame上運行 – nickw444 2012-07-31 11:02:50