Set different font styles for WKInterfaceLabel with multiple lines - swift

I'm developing an apple watch app - it consists of two tables that contain labels.
These labels have two lines of text, I want the second line of text to have a different font style to the top line
How can I do this in swift?
Thanks everyone

The easiest way to do this would be to create two labels in your storyboard, each with their own font style. Then, use setText to set the first and second lines.
Unfortunately, WKInterfaceLabel doesn't provide any typesetting metrics, so there's no built-in method to determine where a line-break occurs. If you need to determine where a line-break occurs, you'll likely have to perform your own typesetting in the Watch extension, then choose to set two different labels or a single label with an NSAttributedString.

Related

How can I manage display and spacing on a Crystal Report where I have to display images between the text field?

I have a field that I'm displaying on a report that is a combination of text and codes that represent an image. Some of those icons have ascii symbols that I've used a replace formula to display them as their ascii version. For two or three of the images, I have no luck and have to display a mini picture for the representation.
The codes being sent are something like:
^he^ = ♥ ^st^ = ⭐ ^cl^ = 🍀 etc...
So for the clover leaf, there is no emoji support in my version of Crystal for clover leaves, and the ascii icon I found online for it just shows the empty square icon when an emoji isn't supported.
My workaround for this is to have a formula that converts all my icons to the appropriate ascii where supported, and to leave two blank spaces for the unsupported icons.
>stringvar gift_msg;
>gift_msg:= {DataTable1.gift_field};
>gift_msg := replace(gift_msg,"^CL^"," ");
>gift_msg := replace(gift_msg,"^HE^","♥");
>gift_msg := replace(gift_msg,"^ST^","★");
>gift_msg
I then put a suppression formula on each image that looks like this:
>mid({DataTable1.gift_field},2,4)<>"^CL^"
So I duplicated the image along the length of the field and increment the mid formula to match the field. I also set the font to Consolas so that it's fixed width to remove any surprises in spacing. My issue is that this still creates very strange spacing, and I'm almost certain there's a much easier way to do this.
One option is to use a free service such as Calligraphr.com to convert your image to a font.
Given that your image relies on several colors, the font option might not work.
Another option is to build the expression as html with image source directives where you need them. You would then need a create or use a 3rd-party UFL to convert the full expression to an image that you can load on the fly using the Graphic Location expression. At least one of the UFLs listed by Ken Hamady here provides such a function.

What does it mean for a CTLine to have "string access"?

I'm trying to solve a hairy problem with UILabel, and I've gotten most of it figured out, except for one thing: I'm having a challenge understanding what it means for a CTLine to have "string access".
The method that I'd like to use is CTLineGetOffsetForStringIndex. Here's a link to the documentation for the method.
Here's the part of the documentation that I don't understand (emphasis is mine):
The primary offset along the baseline for charIndex, or 0.0 if the
line does not support string access.
When I'm running this method, I'm getting 0.0 back, so I guess that means the line doesn't support string access - but what does that mean, exactly?
The statement "the line does not support string access" may be inferred as meaning that the line of text may not be treated as a sequence of characters that may be accessed by the index of each character.
This may open up a large discussion about visual characters versus non-visual characters, and glyphs versus characters. But to simplify the discussion, assume that a line of text may have one of the following states:
more than zero characters (characters which translate to either glyphs or whitespace within the same line) are present in the line of text in question
there are no characters in the line of text which occupy any "space"
Now to provide some rationale for this inference.
Apple's documentation provides a description of Text Kit, upon which UILabel is built:
The UIKit framework includes several classes whose purpose is to display text in an app’s user interface: UITextView, UITextField, and UILabel, as described in Displaying Text Content in iOS. Text views, created from the UITextView class, are meant to display large amounts of text. Underlying UITextView is a powerful layout engine called Text Kit. If you need to customize the layout process or you need to intervene in that behavior, you can use Text Kit. For smaller amounts of text and special needs requiring custom solutions, you can use alternative, lower-level technologies, as described in Lower Level Text-Handling Technologies.
Text Kit is a set of classes and protocols in the UIKit framework providing high-quality typographical services that enable apps to store, lay out, and display text with all the characteristics of fine typesetting, such as kerning, ligatures, line breaking, and justification. Text Kit is built on top of Core Text, so it provides the same speed and power. UITextView is fully integrated with Text Kit; it provides editing and display capabilities that enable users to input text, specify formatting attributes, and view the results. The other Text Kit classes provide text storage and layout capabilities. Figure 8-1 shows the position of Text Kit among other iOS text and graphics frameworks.
Figure 8-1 Text Kit Framework Position
Text Kit gives you complete control over text rendering in user interface elements. In addition to UITextView, UITextField and UILabel are built on top of Text Kit, and it seamlessly integrates with animations, UICollectionView and UITableView. Text Kit is designed with a fully extensible object-oriented architecture that supports subclassing, delegation, and a thorough set of notifications enabling deep customization.
The answer to the related question mentions several classes such as NSTextStorage, NSLayoutManager, and NSTextContainer.
Consider that the UILabel uses all the above classes to provide the end result of displaying text in the parent UIView, which the end user sees on the screen. A layout manager (an instance of NSLayoutManager) coordinates data flow between the text view, the text container, and the text storage, resulting in the display of characters in the view. The layout manager maps the characters to glyphs, and figures out which lines to use to lay out the glyphs. The layout manager also figures out how to display things like underline and strikethrough, which are not part of the glyphs.
Important to this discussion is the fact that the Layout Manager lays out lines of text. If that line of text is selectable, the user may select visible characters in the line. In this particular case, there is "string access" for the line.
A similar concept is the method posted in the solution to related question:
func boundingRect(forGlyphRange glyphRange: NSRange, in container: NSTextContainer) -> CGRect
Returns a single bounding rectangle (in container coordinates) enclosing all glyphs and other marks drawn in the given text container for the given glyph range, including glyphs that draw outside their line fragment rectangles and text attributes such as underlining.
Finally, the reference discussion for the function CTLineGetOffsetForStringIndex speaks about graphical offsets which are suitable for drawing custom carets. The carets may be used to show insertion points or text selection. The primary and secondary offsets may be thought of as beginning and end indices for a string -- a sequence of characters. If there is no sequence of characters for a given line, there can be no selected characters, no carets, no range of glyphs. Therefore no "string access".

Star symbol too small in a dialer-like view

I'm trying to create a dialer-like application:
I'm using [UIFont systemFontOfSize:33]. The problem is that the Asterisk symbol is too small in comparison to the numbers and '#'.
I printed 123*# in all 61 available iOS6 fonts and the star is smaller than other chars in all of them.
Does somebody have an idea how to solve this?
One thing I tried is changing font size only for * button. That works, but when I hit this button it appears small [off course] in the input above...
Hope my Question is clear.
Thanks.
Use a different character for the display. In Xcode, click on the Edit menu and select Special Characters. When the character viewer appears, type "asterisk" into the search field. Try one of the many other related symbols.
Depending on how you do this, you may need to replace the used symbol with a proper asterisk internally to use the result in a tel URL.
You can use attributedString and change the font size to big enough of all asterisks

store and fetch bold/italic font from sqlite database

I tried by make Excel file & import as a csv file in sqlite. But it shows me in normal font rather than bold or italic font.
In my app, I uses the sqlite database and fetches data from it. I want to display some text in italic font,How can i do that??
Does Sqlite supports Italic?
yOu should store data with rules, as in case html we store it as <b>topic/b><i>this is topic</i> i mean by adding proper tagging before save.
I am not share about ios or xcode how but you should add some extra information to text before saving the text.
When you read bold text, you are interpreting a "strong" meaning. This strong meaning can be emphasized in a number of different ways (for instance, all caps: BOLD). Your text shouldn't contain information about how the information is presented (style), but it SHOULD contain information about the meaning (structure). Keeping these two separate gives you more flexibility to change how the text is presented if, say, you wanted to change your website template or application design. You could choose to display strong text as bold, all caps, all caps and underlined, etc. on a whim.
I recommend some subset of HTML, as it is structural by nature and very widely used. In HTML, the bold tag exists (<b>; however, it is stylistic, so the <strong> tag is recommended to encode the strong meaning instead).
Databases don't support encoding; however, you can encode the text yourself before sticking it in the database. Here is an example of an HTML-encoded string:
<p><strong>An HTML-encoded string</strong> inside a paragraph.</p>
When you extract it, you could choose to represent the strong text as bold:
An HTML-encoded string inside a paragraph.
Or as CAPS:
AN HTML-ENCODED STRING inside a paragraph.
Or even italic caps:
AN HTML-ENCODED STRING inside a paragraph.
There are many other ways to encode structure, including Mark Down (I believe that's what StackOverflow uses).
where you want to display it? in some label , textfiled or some other? change font type there where you want to display it
For example if you want to display it in UILable
then change the font type of UILabel
[<lblname> setFont:[UIFont boldSystemFontOfSize:<whatever_you_want>]];
It's your bad logic to fetch bold text from database.
Enjoy Programming

How to make the 1st line in certain amount of text in a Label bold?

I have about 400 character length string with a heading called Details. In this 'Details' is to be bold and of fontsize 19. While all the remaining text starts in the next line and should be of fontSize 18 like the contents. How can I do all this by using a UILabel?
Plz help me...
You can't do it with a stock UILabel as of SDK 3.2. You can create an NSAttributedString that specifies particular styles (like bold) for particular parts of the string, but there isn't a simple way to actually render it. This is unlike In Max OS X, which has NSAttributedString(AppKitAdditions), which allows you to draw an attributed string in a single line of code. If you want to render it, you can, but you'll have to delve into one of the lower level APIs (such as Core Text).
You're probably much better off using two UILabels. Make the first one bold, and make the second one cover multiple lines.
Since UILabel does not support attributed strings, you have two options:
Subclass UILabel and override -drawRect:
Create 2 UILabels, one of which will display the heading, the other showing the rest of your text. You can choose to wrap the two labels into your own view if necessary.
You could use a UIWebView with an HTMLString of <strong>First part</strong> second part