0

I am writing an app that requires labels w/ musical accidental symbols, called sharp and flat (♯ and ♭, respectively). Specifically, I need a label that says c♯. It is irrelevant to the question what these two symbols mean within a musical context. My app's main font is Open Sans. However, because Open Sans doesn't specify a character for the sharp and flat symbols, it uses a generic sharp and flat symbol that I find unattractive. However, I know that Helvetica Neue (or the iOS system font) has some well made symbols for sharp and flat, so I decided to change the label's text to an attributed string so I could make the c Open Sans, and the ♯ Helvetica Neue (both size 24). I did this through the interface builder. Even though everything looks exactly the way I want in the storyboard, when I launch it in the iOS Simulator, the labels with attributed strings are significantly shrunken from the other labels. I should note that the label has 3 AutoLayout constraints, though these contrasts are positionally related only, not size related.

Things I have tried (unsuccessfuly):

  • Using only one font
  • Doubling the font size (was too big)
  • Removing autolayout constraints

I would greatly appreciate it if someone could explain how to correctly create these labels. I am happy to provide any more information that is needed.

Thank you

ericmarkmartin
  • 717
  • 1
  • 8
  • 19
  • I added Open Sans in to the files and added it to the .plist. It works on the generic labels and is in the storyboard as a selectable font. – ericmarkmartin Dec 27 '14 at 00:40
  • Okay, excellent. Can you put a screenshot somewhere or post an example project on github? There need to be enough info so that others can see and reproduce the problem... – matt Dec 27 '14 at 00:44
  • Why did using one font not work, what was the problem? – zaph Dec 27 '14 at 00:47
  • It sounds like you are using several labels next to each other to achieve your result, is that so? As matt stated please provide more information, add it to your question.. – zaph Dec 27 '14 at 00:49
  • @matt, I think you misunderstood my comment. Adding it to the project did not fix the problem, I was simply saying that I had already done that because that negates the fact that it is not a built-in system font. In response to my lack of pictures, my reputation is too low. – ericmarkmartin Dec 27 '14 at 00:51
  • @Zaph, I am not using multiple labels, as that would defeat the purpose of an attributed string. I did, however, figure out my own answer. See below. – ericmarkmartin Dec 27 '14 at 00:54
  • 1
    No, I understood perfectly. Read again what I asked you to do, please. Do you want help or not? – matt Dec 27 '14 at 00:54
  • I'm sorry, you are right. I misunderstood your comment. I apologize. – ericmarkmartin Dec 27 '14 at 00:59

1 Answers1

4

I discovered that the problem is that NSAttributedString does not (yet) support custom fonts through Interface builder. It looks like I will have to subclass. This question essentially boils down to be the same as this one: Attributed string with custom fonts in storyboard does not load correctly

Community
  • 1
  • 1
ericmarkmartin
  • 717
  • 1
  • 8
  • 19
  • That's not at all what that question is about. It says that showing your text _in Xcode_ doesn't work for custom fonts. But NSAttributedString certainly does support custom fonts. – matt Dec 27 '14 at 00:53
  • Not through storyboard. Sorry for the confusion. – ericmarkmartin Dec 27 '14 at 00:54
  • Okay, I see your point. I have never liked the Xcode interface for making an attributed string so I've never used it. If I want to make an attributed string I always make it in code. – matt Dec 27 '14 at 00:58
  • Thanks for the tip. I'll keep that in mind for the future. It appears like I'm going to have to do this with a custom IBDesignable class. I could probably just do it with a regular subclass but I like for my Storyboard to look the same as the actual build (pet peeve I guess?). – ericmarkmartin Dec 27 '14 at 01:01