<分区>
我想将内阴影应用于 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
给了我们一个外部阴影,而不是内部阴影(除非我遗漏了什么)。