How can I assign a custom UIButton character using Unicode?

I want to assign some UIButtons using Unicode, I tried it differently but none worked for me. Please check the screenshot of what I want to achieve

enter image description here

what i tried for

 [button setTitle:[NSString stringWithFormat:@"\u27F2"] forState:UIControlStateNormal];

 [button setTitle:[NSString stringWithFormat:@"\U27F2"] forState:UIControlStateNormal];

 [button setTitle:[NSString stringWithFormat:@"\U+27F2"] forState:UIControlStateNormal];

 [button setTitle:[NSString stringWithFormat:@"U+27F2"] forState:UIControlStateNormal];

      

In all cases, my button shows a question mark with a field.

enter image description here

Any help would be appreciated. thank

+3


source to share


3 answers


Use "\u{27F2}"

or in obj-c: @"\u27F2"

to get a Unicode string. If it doesn't display or does not show a question mark, then the font you are using does not support that character. Then find the font family that has that character (letter).

Swift 3.0

let button = UIButton(frame: CGRect(x: 0, y: 0, width: 66, height: 66))
button.setTitle("\u{27F2}", for: [])
button.titleLabel?.font = UIFont(name:"AvenirNext-UltraLight", size: 46)

      



Objective-C:

[button setTitle:@"\u27F2" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"AvenirNext-UltraLight" size:21.0];

      

+4


source


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



0


source


I hope you are already, but first make sure you have the select button type as custom for the uibutton, then try any of these:

  • use case + keyboard shortcut for IB
  • REPLACE [setTitle button: [NSString stringWithFormat: @ "\ u27F2"] forState: UIControlStateNormal]; WITH THIS [button setTitle: [NSString stringWithUTF8String: @ "\ u27F2"] forState: UIControlStateNormal];
  • use a unicode font like "Symbola"
-1


source







All Articles