UIButton bottom shadow

后端 未结 11 1168
-上瘾入骨i
-上瘾入骨i 2020-12-12 14:14

I have a UIButton which is very similar to the standard iOS keyboard alphabet button.

I am not sure how to create a shadow only for the bottom layer li

11条回答
  •  生来不讨喜
    2020-12-12 14:40

    You can mix the cornerRadius and shadow properties. I tested it on iOS 8.

    Objective-C:

    [self.globeButton setImage:[UIImage imageNamed:@"Globe"] forState:UIControlStateNormal];
    self.globeButton.backgroundColor = [UIColor colorWithRed:171 green:178 blue:186 alpha:1.0f];
    // Shadow and Radius
    self.globeButton.layer.shadowColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.25f] CGColor];
    self.globeButton.layer.shadowOffset = CGSizeMake(0, 2.0f);
    self.globeButton.layer.shadowOpacity = 1.0f;
    self.globeButton.layer.shadowRadius = 0.0f;
    self.globeButton.layer.masksToBounds = NO;
    self.globeButton.layer.cornerRadius = 4.0f;
    

    Swift:

    globeButton.setImage(UIImage(named: "Globe"), forState: .Normal)
    globeButton.backgroundColor = UIColor(red: 171/255, green: 178/255, blue: 186/255, alpha: 1.0)
    // Shadow Color and Radius
    globeButton.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
    globeButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
    globeButton.layer.shadowOpacity = 1.0
    globeButton.layer.shadowRadius = 0.0
    globeButton.layer.masksToBounds = false
    globeButton.layer.cornerRadius = 4.0
    

    Result:

    UIButton + iOS Keyboard style

提交回复
热议问题