uilabel

Line Breaks and Number of Lines in Swift Label (Programmatically)

南笙酒味 提交于 2020-07-16 16:29:19
问题 By selecting a Label in a StoryBoard, I can select Line Break to be Word Wrap and change number of lines to be more than 1. How can I do that Programmatically in Swift? 回答1: You can do this to set it programmatically label.lineBreakMode = NSLineBreakMode.ByWordWrapping label.numberOfLines = 3 Swift 3/4 label.lineBreakMode = .byWordWrapping label.numberOfLines = 3 回答2: If you want the label to have multiple lines, do this: var myLabel:UILabel = UILabel(frame: CGRectMake(7, 200, 370, 100))

Setting UILabel text to bold [duplicate]

有些话、适合烂在心里 提交于 2020-07-04 05:50:18
问题 This question already has answers here : How do I set bold and italic on UILabel of iPhone/iPad? (18 answers) Closed 5 years ago . How do you set the text for a UILabel to bold in Swift programmatically? My code so far: var label = UILabel(frame:theFrame) label.text = "Foo" 回答1: Use font property of UILabel : label.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0) or use default system font to bold text: label.font = UIFont.boldSystemFont(ofSize: 16.0) 回答2: Use attributed string: // Define

iOS UILabel bounding rectangle not sized correctly

不问归期 提交于 2020-06-29 13:06:09
问题 I have a UILabel (as highlighted in yellow), which has the following conditions applied to it. Label has variable text length Font set to 40 Minimum font-size set to 20 Number of lines set to 3 Although this looks like a duplicated question I believe it is not. The issue I am having is that when the text exceeds the available 3 line length after being sized-down to 20 points, the UILabel's bounding box is sized incorrectly (i.e. note the extraneous spacing above and below the text). The end

Label line break not working properly in xcode

浪子不回头ぞ 提交于 2020-06-29 03:59:30
问题 I have a label which shows the pink area on the screen. However, the word "gender " is not shown in the top line even if it has enough space. Why is it not showing up in the first line itself? What I need label.text = @"Do you believe in gender equality"; Label 回答1: The UILabel is working as intended by preventing an orphaned word so it’s more readable. This was introduced in iOS 11. Apple must disable it for iMessage because they probably intend this behaviour for long articles of text, not

UILabel get current scale factor when minimumScaleFactor was set?

落花浮王杯 提交于 2020-06-27 07:12:17
问题 I have a UILabel and set: let label = UILabel() label.minimumScaleFactor = 10 / 25 After setting the label text I want to know what the current scale factor is. How can I do that? 回答1: You also need to know what is the original font size, but I guess you can find it in some way 😊 That said, use the following func to discover the actual font size: func getFontSizeForLabel(_ label: UILabel) -> CGFloat { let text: NSMutableAttributedString = NSMutableAttributedString(attributedString: label

UILabel get current scale factor when minimumScaleFactor was set?

半腔热情 提交于 2020-06-27 07:12:04
问题 I have a UILabel and set: let label = UILabel() label.minimumScaleFactor = 10 / 25 After setting the label text I want to know what the current scale factor is. How can I do that? 回答1: You also need to know what is the original font size, but I guess you can find it in some way 😊 That said, use the following func to discover the actual font size: func getFontSizeForLabel(_ label: UILabel) -> CGFloat { let text: NSMutableAttributedString = NSMutableAttributedString(attributedString: label

How to add dots (ellipses) to LabelView as in the table of contents of a book

点点圈 提交于 2020-06-26 12:25:40
问题 I have stackView which contains few labelViews in each of which two words are written. And I want them to be separated by an ellipsis across the entire width of labelView. As a result: one word close to the left, another - to the right, and dots between them. Note: the label can take up several lines if the words length is long. EDIT Here filling my stackView for ingredient in ingredients { let textLabel = UILabel() textLabel.backgroundColor = UIColor.yellow // just for my needs textLabel

How to remove the extra padding below an one line UILabel

独自空忆成欢 提交于 2020-06-26 07:16:04
问题 I wanna to use a UILabel to show some words which is sent from Server,these words which i set them as NSMutableAttributeString sometimes only occupy one line (only in this case, the problem comes). I intend to get the exact space which the label would take up,but when the label only takes up one line,and very important — i set the NSMutableAttributeString with lineSpacing (10px,NSMutableParagraphStyle),but this,unexpectedly, would also works when even there is only one line here — the problem

How to remove the extra padding below an one line UILabel

不羁岁月 提交于 2020-06-26 07:14:37
问题 I wanna to use a UILabel to show some words which is sent from Server,these words which i set them as NSMutableAttributeString sometimes only occupy one line (only in this case, the problem comes). I intend to get the exact space which the label would take up,but when the label only takes up one line,and very important — i set the NSMutableAttributeString with lineSpacing (10px,NSMutableParagraphStyle),but this,unexpectedly, would also works when even there is only one line here — the problem

Customize navigation bar by adding two labels instead of title in Swift

半世苍凉 提交于 2020-05-24 12:01:05
问题 I am trying to add two labels in the place where the title is shown in navigation bar, but I am struggling to do so. It would be very nice if I could achieve this with storyboard but as I can see I cannot do it. As I have seen I need to use navigationItem but I do not know how exactly to do that. If anyone have any example or if anyone could explain me more specifically how to do so would be wonderful. And I need to mention that I am completely unfamiliar with Obj-C, so any help would need to