1

On iOS 9 I used to do this

[button setTitle:@"" forState:UIControlStateNormal];

Problem: now I'm building with the iOS 10 SDK and instead it is showing three dots next to each other. It works fine on UILabel. Also tried this answer, but didn't work.

Any idea how you'd do emoji in iOS 10? Swift answers would be great too.

enter image description here

Community
  • 1
  • 1
yoeriboven
  • 3,541
  • 3
  • 25
  • 40
  • 2
    Works fine for me, but ellipsis tend to imply that the button's extents aren't big enough for the text that's being used. You should check the constraints that the button's operating on. – Anya Shenanigans Sep 12 '16 at 10:49
  • @VarunKumar No, that is not a duplicate. – rmaddy Sep 12 '16 at 15:09

3 Answers3

3

iOS 10 seems to use an ever so slightly bigger font. Either make your button bigger or setup the button's label to auto adjust the font's size to fit its title.

A label shows ... by default when the text won't fit.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

You can use unicode to set emoji as button title see below code:

[self.btn setTitle:@"\U0001F47B" forState:UIControlStateNormal];

Output:

enter image description here

Just replace + character with three 000 and backward slash as prefix of unicode. Here is the list of emoji with its unicodes.

vaibhav
  • 4,038
  • 1
  • 21
  • 51
  • 1
    Sorry but this answer won't fix anything. There's no reason that simply changing the Emoji literal to it's Unicode escape sequence will make any difference. At runtime this code is the same as the OP's code. The Unicode escape will be translated to the literal characters at compile time. – rmaddy Sep 12 '16 at 14:46
  • @rmaddy feeling informative to have your contribution here ..thanks :) – vaibhav Sep 12 '16 at 14:52
-1

Do nonlossy string encoding:

NSData *Data=[@"youremojistring" dataUsingEncoding:NSNonLossyASCIIStringEncoding];
        NSString *result=[[NSString alloc] initWithData:Data encoding:NSNonLossyASCIIStringEncoding];
[button setTitle:result forState:UIControlStateNormal];
jagdish
  • 166
  • 5