uilabel

UILabel auto scroll like a marquee

限于喜欢 提交于 2021-02-02 09:45:33
问题 I am trying I make a UI label auto scroll the text that is inside it like a marquee. The below code works depending on what kind of text/content I throw at it. I can't tell what works and what does not. What happens is that the label does not show anything, then suddenly scrolls the text at an extremely high speed that you can't read it. For some reason, this works perfectly on the iPhone but not on the iPad. I am guessing because the text I am putting at the iPhone is always way bigger than

swift how to get UILabel align to top left

本秂侑毒 提交于 2021-01-29 19:03:41
问题 I'm making a trivia app that prints the question out word by word, and currently it starts at the middle of the UILabel and pushes the previous text upward. I'm trying to find out if I can start the first word at the top left of the label, the continue printing the rest. func printQuestion () { var str = quizbrain.getQuestionText() var arr = str.components(separatedBy: " ") var count = 0 Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { (t) in self.questionLabel.text! += " " + arr

Expression type '@lvalue String?' is ambiguous without more context when += to UILabel.text

我是研究僧i 提交于 2021-01-29 11:43:08
问题 I am trying to add the string "7" to a label when someone tabs the button labeled 7. But when using += "7", it gives me the error "Expression type '@lvalue String?' is ambiguous without more context", when using the operator = "7" it works fine. Why doesn't += "7" work? class NumberPadController: UIViewController { @IBOutlet weak var valueLabel: UILabel! /// set value in main vc and return to that. @IBAction func doneEntering(_ sender: Any) { guard let valueString = valueLabel.text, let

<b> tag not working in UILabel attributed string

只愿长相守 提交于 2021-01-29 02:27:39
问题 I am displaying html string into attributed text if UILabel but few of the tags are not working in UILabel like lineLabel.numberOfLines=0; NSString* html = self.offerArray[0][@"description"]; NSString * htmlString = [NSString stringWithFormat: @"%@%@</body></html>",kHTMLHeadOffer,html]; htmlString = [htmlString stringByReplacingPercentEscapesUsingEncoding:NSUnicodeStringEncoding]; NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[htmlString

Detect tap for UILabel with Autoshrink to minimum font size enabled

折月煮酒 提交于 2021-01-29 00:29:42
问题 I am using the following UITapGestureRecognizer that I modified so others could copy and paste to see the same output as me. extension UITapGestureRecognizer { func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool { // Create instances of NSLayoutManager, NSTextContainer and NSTextStorage let layoutManager = NSLayoutManager() let textContainer = NSTextContainer(size: CGSize.zero) //let mutableAttribString = NSMutableAttributedString(attributedString: label

Detect tap for UILabel with Autoshrink to minimum font size enabled

隐身守侯 提交于 2021-01-29 00:28:12
问题 I am using the following UITapGestureRecognizer that I modified so others could copy and paste to see the same output as me. extension UITapGestureRecognizer { func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool { // Create instances of NSLayoutManager, NSTextContainer and NSTextStorage let layoutManager = NSLayoutManager() let textContainer = NSTextContainer(size: CGSize.zero) //let mutableAttribString = NSMutableAttributedString(attributedString: label

NSLayoutManager returns incorrect character index when tapping on LTR text in RTL attributed text

僤鯓⒐⒋嵵緔 提交于 2021-01-28 08:51:58
问题 I wrote code to detect if the user taps within a specific range in UILabel . It seems to be working in most cases, but I have noticed that tapping the last line of an attributed text creates inconsistent results. public static bool DidTapRange(this UITapGestureRecognizer recognizer, UILabel label, NSRange range) { using (var ts = new NSTextStorage()) { var lm = new NSLayoutManager(); var tc = new NSTextContainer(new CGSize(label.Frame.Width, double.MaxValue)); lm.AddTextContainer(tc); ts

Bottom-align the text of a sequence of UILabels within a horizontal UIStackView

ε祈祈猫儿з 提交于 2021-01-28 04:37:37
问题 How do I programmatically align the text of a sequence of UILabels within a horizontal UIStackView so that all text is at the bottom of the views? Below is an image of what I have and what I want. I already know how to create the views, I just can't figure out what properties or constraints are needed to get the text to align on the bottom of the views. Thanks. 回答1: Related to what @mahbaleshwar mentioned, UILabels always center align. However, UIStackView has some properties that will help

How to align UILabel text in paragraph

戏子无情 提交于 2021-01-27 07:21:56
问题 I have a small issue in setting text alignment as per client requirement. Client want text to be aligned in paragraph manner with numbers in separate line. Please see the below image the number have 19 pixels padding and text aligned in paragraph manner with 41 pixels padding. If we set left alignment to label we will get the second line below the numeric. I tried search for solution but not able to succeed. Thanks in advance. 回答1: You'll need to set different attributes for the question part

NSAttributedString text always sticks to bottom with big lineHeight

点点圈 提交于 2020-12-13 03:29:41
问题 I'm trying to implement by-design labels coming from Sketch e.g. I need text styles with font size = 19 and line height = 50. So I ended up using NSAttributedString with NSMutableParagraphStyle but was stopped by problem with text being sticked to bottom of UILabel I've already tried to use lineHeightMultiple and lineSpacing but those didn't give me the line height I wanted so I ended up using minimumLineHeight and maximumLineHeight equal the same Here is my approach to make