Programmatically adding a shadow to a UIButton label

前端 未结 6 562
盖世英雄少女心
盖世英雄少女心 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:14

    The other answers do not properly set the shadow color (I suspect they didn't notice because they were trying to set the shadow color to what it is by default, black.)

    This code worked for me to add a white shadow to the text of my button:

    myButton.titleLabel.shadowOffset = CGSizeMake(0, 1);
    [myButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
    

提交回复
热议问题