Note that there are some explanatory texts on larger screens.

plurals
  1. POA UILabel with rounded corners, drop shadow and background pattern
    text
    copied!<p>I have been trying every single method I found but I wasn't able to make it. I simply want to make a label with rounded corners, a drop shadow with a background pattern. The shadow works only if I do not want rounded corners. I can't get them both together!</p> <p>Here is my code with the shadow: </p> <pre><code>label.text = msg; label.textAlignment = UITextAlignmentCenter; label.frame = CGRectMake(20,10,280,40); label.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"msg_box_bg.png"]]; [label.layer setCornerRadius:10]; [label.layer setMasksToBounds:NO]; /* Shadow */ label.layer.shadowColor = [UIColor blackColor].CGColor; label.layer.shadowOpacity = 0.6; label.layer.shadowOffset = CGSizeMake(0,0); label.layer.shadowRadius = 3; </code></pre> <p>This gives me shadow without rounded corners. But if I use</p> <pre><code>[label.layer setMasksToBounds:YES]; </code></pre> <p>This will give me rounded corners with no shadow. I have taken the advise to use a shadow path, so the code with the shadow path looks like this:</p> <pre><code>label.text = msg; label.textAlignment = UITextAlignmentCenter; label.frame = CGRectMake(20,10,280,40); label.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"msg_box_bg.png"]]; [label.layer setCornerRadius:10]; [label.layer setMasksToBounds:YES]; /* Shadow */ label.layer.shadowColor = [UIColor blackColor].CGColor; label.layer.shadowOpacity = 0.6; label.layer.shadowOffset = CGSizeMake(0,0); label.layer.shadowRadius = 3; label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.frame cornerRadius:10]CGPath]; label.layer.shouldRasterize = YES; </code></pre> <p>This code does give me rounded corners but no shadow. Any suggestions?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload