In reference of Swift: make ellipsis continually retype in label? Tough label "animation"?, I am trying to animate little image views to jump in and scale at the foot of some text in a label to create the effect referenced in the above question.
To do this I need to add these image views inline in a label and then animate them using UIView.animateWithDuration and some scaling, etc.
I do not know how to add these images inline in the label so they appear in the same place on the label regardless of device - how can I add image views inline a label in Swift?
You don't "add image views"; you add images as part of the label's text. Use an NSAttributedString. You will need an NSMutableAttributedString so that you can modify it. Make an NSTextAttachment and set its image to your image (needs to be the desired size beforehand, easy to do). Call NSAttributedString(attachment:) to make a second attributed string consisting of the inline image, and insert that new attributed string at the desired index into your original attributed string. Set the label's attributedText to that.
Related
I have this interface with multiple UILabels.
On view loading i populate white labelled values with some data from a db.
The problem is, some of that fields are potentially too long for the interface, so i'd like to compute the total height of one label once the text is word wrapped and reposition the 2 labels below (shifting the Y coordinate) accordingly to the previous label's height.
All of this should go inside a UIScrollView to let the user scroll those labels vertically.
Any chance i can do this easily with some control i still don't know, or do i have to do it manually?
Thanks
You'll need to use the NSString UIKit Additions to compute the height you need to set on your UILabel, and then adjust the other controls appropriately.
Specifically, I think you want to use sizeWithFont:forWidth:lineBreakMode: to get the rect for your UILabel.
Alternatively, you could use a UIWebView and display the information as HTML. I don't know if it's necessarily less work, but you'll get a layout that automatically adjusts to the size of its contents.
What i Need to do for our project is to Display several UIScrollViews in a View and weithin the scrollView a Headline and a Short Text.
I Know how to add a Label to the UIscrollview, but how Gould i handle the Case that the Headline-Label is too Long and wraps to a Second Line.
You can determine the space needed for the headline text by calling -[NSString sizeWithFont:] or one of its variants. Then size and position the labels dynamically in your code (and set their numberOfLines property to 0).
Alternatives:
Use a UIWebView to display formatted text (HTML).
Use Core Graphics to draw the text directly into the view (e.g. [NSString drawAtPoint:withFont:]).
Use Core Text to format and draw the text (quite complicated).
How can I add an indent or offset to text inside a UILabel? It needs to be a specific pixel size, independent of the font size.
you could create another UILabel and then set each label's frames to be a certain width apart, that way it could be done dynamically rather easily if thats what you are trying to accomplish.
I want to draw a text with different colors and the only way that I've found for do it is to split every piece of string-color in differents UILabels, so currently now I have four UILabels one after another, lets say, label1, label2, label3 and label4.
The problem with that is with the size and the position of every labels, I've not found an automatic way for do it.
The only way is:
Set the text inside all the labels
Ask for the width of all the labels with this new text
Resize all the labels with this new width
Move label2 to label1.x + label1.width, and so on
This is really the only way in iPhone for do that?
I came from Android and there is a "wrap_content" property for every view and "relative_layouts" where you can define something like.. put label2 rightOf label1. So I'm looking of something simple and automatic like that, but in iPhone.
Thanks!
Depending on your application, you might want to consider a single UIWebView instead. Then you can style the content of it with HTML and CSS.
I am new to iphone development.I have created three labels in a cell and i have just displayed the text in the corresponding labels , but i want to display the full text in the label.I am not able to see the full text,So is there any possibility for breaking the text and show them in two lines.I am not displaying any static text .I am getting the text dynamically from the website and displaying it in the label.Please help me out.Thanks.
set label's numberOfLines property to 2 (or to 0 to have any number of lines you need)
set label's lineBreakMode property (e.g. to UILineBreakModeWordWrap)
make sure that label's height is enough to contain 2 (or more) lines of text