I have custom Chivo font, added via cocoapod.
So, in xib I can find it using Title Plain, as you can see:
But if I need to use Attributed Title (for example to use 2 types: regular and bold in same string),
I can't find Chivo font:
So how to fix this? I sure can use it from code, but wonder if it can work in described way.
Thanks for help!
Related
I have a link within an attributed string that is being then set for a textview. For Accessibility purpose, I want that link to be called out as a link trait, is it currently possible for an attributed string to call out different traits within the string? If not what could be an ideal solution to do that then?
You can look for all the "style runs" of attributes within the text view's attributed text by calling attributes(at:longestEffectiveRange:in:) repeatedly until you come to the style run you want. Thus you can locate the link and obtain its value.
The Apple documentation says that for iOS an app can use text styles and dynamic font type so text size automatically adjusts to the users reading preferences.
I have a text style Body and set Dynamic Type to true so that it automatically adjust the text size. This works good.
This text I would also like to make appear bold. I haven't found a way yet how to achieve this either by code or in the Interface Builder.
Is there a way to achieve a "bold dynamic font type"?
Ok, it seems the documentation provides a hint. For using custom fonts, I consider a bold font as a custom font now, one can use the UIFontMetrics class.
If I pass a "bold custom font" to the scaledFontForFont method of UIFontMetrics class I get the desired result with the dynamic font type UIFontTextStyleBody.
UIFont* boldSystemFont = [UIFont boldSystemFontOfSize:17];
myLabel.font = [[UIFontMetrics metricsForTextStyle:UIFontTextStyleBody] scaledFontForFont:boldSystemFont];
So far I only see this way using code. No idea if this could somehow be setup in the Interface Builder as well.
I am trying to create a custom keyboard using the app keyboard extension. I am happy with the layout but the output is depended on the UITextField's font.
Is there a way to force a different font (use special characters?) while using the keyboard ?
Thank you
It depends.
Text field (or any other view that draws text) uses 2 informations on how to show some text. One is the sequence of characters called String and the other one is how the string should be represented. The second one is then split it things like fonts, colors, line height, line breaking and wrapping...
So the keyboard alone is not enough to for instance present a certain part of word using different fonts. You need at least a bit of access to the item that represents the text. So if you have no access to your text field then the answer is; No, you can not fore a different font when using different keyboard.
If you do have the access then the answer should lie in NSAttributedString. It is a string you can assign to most items under attributedText. This class wraps your raw string and can add many properties to parts of text you want to change. That includes using a different font.
Another approach would be using HTML tags. Again you will need to process this using for instance NSAttributedString or display it with another element like web view.
I would try it with using NSAttributedString. Hook up to delegate and implement textField(: shouldChangeCharactersIn: replacementString:. The implementation itself may still not be easy though.
I want to insert a URL hyperlink into a UITextField that has different display text.
This is super easy in html:
Go To Google
How can I do this in iOS?
You can change the text style inside your UITextField via an attributed string sent to the text field's "attributedText" property.
However, what I suspect you really want to do is have a link that's clickable. I would recommend using a UIButton with a custom type (i.e. no border) and you can set the color and the underline style.
But like Evan said, if you have multiple lines of text, it may be smarter to use a UITextField where you set "editable" to NO and turn on the LINK traits (both of these you can do from the object inspector in Xcode).
Alright, so here's what I did to get what I wanted. I used UIWebView, and simply linked it to an html page in the project that has the text, and hyperlink at the bottom with different text displayed.
Answer is here :
If you want it as clickable Hyperlink,
NSString *string = #"Go To Google";
You need to add "BACKWARD SLASH" before ". That's it.
I looked at a few examples here on OS and also followed this one but what I wanted to know is how I can set a custom font for only one specific label.
This line is supposed to change the font:
[UIFont fontWithName:#"Cloister Black" size:64.0]
But I don't want everything to be affected. Any ideas how I do this?
Setting the font on a label is as easy as modifying that label's "font" property (and I've linked Apple's documentation for you).
E.G.:
labelIWantToModify.font = [UIFont fontWithName:#"Cloister Black" size:64.0];
And I'm hoping you're referring to that one specific label, and not a piece or part of the string that appears within the label, which is a separate (attributed string) thing.