2012-11-29 46 views
1

因爲UIButton.titleLabel.shadowOffset特性使得陰影尖銳,我改變drawTextInRect方法來創建自定義半徑的陰影象下面這樣:UIButton.titleLabel陰影剪裁

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
float colorValues[] = {0, 0, 0, opacity}; 
CGColorRef shadowColor = CGColorCreate(colorSpace, colorValues); 
CGSize shadowOffset = CGSizeMake(offsetX, offsetY); 
CGContextSetShadowWithColor (context, shadowOffset, radius, shadowColor); 

這工作得很好。它創造了陰影。我改變titleLabel的界限,並呼籲drawTextInRect方法,如:

button.titleLabel.bounds = CGRectMake(button.titleLabel.bounds.origin.x, button.titleLabel.bounds.origin.y, button.titleLabel.bounds.size.width, button.titleLabel.bounds.size.height); 
[button.titleLabel drawTextInRect:button.titleLabel.bounds]; 
[button setNeedsLayout]; 

由於titleLabel界,陰影裁剪。

任何幫助將不勝感激...

回答

0

您是否嘗試過與層相同。我認爲它會對你的問題進行分類,可能你並不需要你做的。

只需將你的按鈕的圖層(CALayer)對象設置爲任何你需要的屬性就可以了。記住,對於使用QuartzCore框架的圖層,你需要導入。

試試吧,在任何情況下只要大聲說出我的意思。