I have a UILabel that I add a shadow to. The UILabel shows up and so does the shadow, but the leftmost shadow is cut off so that it is in line with the edge of the text. I moved the position of the label to see if it was being covered by a view, but everything stayed the same. I also took out the sizeToFit, and it stayed the same. Here is the initialization of the label:
UILabel *scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
scoreLabel.text = text;
[scoreLabel setFont:[UIFont fontWithName:fontName size:fontSize]];
scoreLabel.textColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
scoreLabel.shadowColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];
scoreLabel.shadowOffset = CGSizeMake(-10.0, 2.0);
scoreLabel.clipsToBounds = NO;
[scoreLabel sizeToFit];
scoreLabel.center = CGPointMake(x, y);

I had this problem with a custom font and solved it by subclassing UILabel and adding the shadowOffset to intrinsicContentSize with this override:
override var intrinsicContentSize: CGSize {
get {
let s = super.intrinsicContentSize
return CGSize(width: s.width + abs(shadowOffset.width), height: s.height + abs(shadowOffset.height))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With