Programmatically adding a shadow to a UIButton label

前端 未结 6 568
盖世英雄少女心
盖世英雄少女心 2021-02-04 03:15

I\'m trying to add a 1px black drop shadow to a button label with no luck. I\'ve tried this:self.setTitleShadowOffset = CGSizeMake(0, -1); but I get:

6条回答
  •  一整个雨季
    2021-02-04 04:08

    Here is how to add shadow to the button title in Objective-C with radius property:

    #import     
    
    button.titleLabel.layer.shadowOffset = CGSizeMake(2.0, 2.0);
    button.titleLabel.layer.shadowColor = [UIColor colorWithWhite:0.1 alpha:0.7].CGColor;
    button.titleLabel.layer.shadowRadius = 2.0;
    button.titleLabel.layer.shadowOpacity = 1.0;
    button.titleLabel.layer.masksToBounds = NO;
    

提交回复
热议问题