我想将内部阴影应用于UILabel。我有一个解决方案,但它不够好。任何人有更好的解决方案?将内部阴影应用于UILabel
// UILabel subclass
- (void) drawTextInRect:(CGRect)rect {
CGSize myShadowOffset = CGSizeMake(0, 2);
float myColorValues[] = {255, 0, 0, 1};
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(myContext);
CGColorSpaceRef myColorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef myColor = CGColorCreate(myColorSpace, myColorValues);
CGContextSetShadowWithColor (myContext, myShadowOffset, 5, myColor);
CGContextSetBlendMode(myContext, kCGBlendModeLighten);
[super drawTextInRect:rect];
CGColorRelease(myColor);
CGColorSpaceRelease(myColorSpace);
CGContextRestoreGState(myContext);
}
我熟悉的UILabel层属性,但shadow offset
给了我们一个外的影子,而不是内部阴影(除非我失去了一些东西)。
您是否在myShadowOffset中尝试过负值? – adam 2011-04-28 11:28:02