Adding a drop shadow to NSString text in a drawRect: method without using UILabel

后端 未结 1 1890
猫巷女王i
猫巷女王i 2020-12-14 17:48

I\'d like to add a drop shadow to text drawn using the iOS supplied NSString (UIStringDrawing) category method:

- (CGSize)drawAtPoint:(CGPoint)p         


        
相关标签:
1条回答
  • 2020-12-14 17:58

    It works fine for me with CGContextSetShadow(). Example:

    - (void)drawRect:(CGRect)rect 
    {
        NSString *string = @"Hello World!";
    
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetShadow(context, CGSizeMake(20.0f, 20.0f), 10.0f);
    
        [string drawAtPoint:CGPointMake(100.0f, 100.0f) withFont:[UIFont boldSystemFontOfSize:36.0f]];
    }
    
    0 讨论(0)
提交回复
热议问题