Programmatically adding a shadow to a UIButton label

前端 未结 6 592
盖世英雄少女心
盖世英雄少女心 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条回答
  •  猫巷女王i
    2021-02-04 04:03

    The right property is self.titleLabel.shadowOffset:

    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
    [b setTitleShadowColor:[UIColor purpleColor] forState:UIControlStateNormal];
    b.titleLabel.shadowOffset = CGSizeMake(1.0, 1.0);
    [b setTitle:@"Hello, I'm a Button" forState:UIControlStateNormal];
    b.frame = CGRectMake(10.0, 10.0,300.0, 40.0);
    

提交回复
热议问题