Interval between UILabel

I am trying to set the line spacing to UILabelas indicated by Mike Slutsky here . It works correctly for the text that I specify from the storyboard. When I try to install the code UILabel.textin the code, it returns to the default interval. Can someone help me figure out how to do this:

  • Do not return it by default and use the settings that I specified on the storyboard, or

  • Set the value in the code.

I have seen many use cases NSAttributeand NSParagraph, but since it can now be set in the storyboard, I would expect them to be a simpler answer. Thank you very much for your help!

I installed "Height Multiple" as shown in the link above, and my only code is as follows:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var textView: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        textView.text = "Some example text"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

textView.text, , ( Height Multiple).

+4
4

. . , , , attributedText.

text , , attributedText , , , . , , .

: text attributedText. , attributedText; NSMutableAttributedString, ; , ; attributedText.

, ( lab - textView , ):

let text = self.lab.attributedText
let mas = NSMutableAttributedString(attributedString:text)
mas.replaceCharactersInRange(NSMakeRange(0, count(mas.string.utf16)), 
    withString: "Little poltergeists make up the principle form of material manifestation")
self.lab.attributedText = mas
+11

UILabel

@property(nonatomic, copy) NSAttributedString *attributedText iOS 6.0,

. text , - . , , textColor , , , 0 .

textView.text = "Some example text", . , ,

+1

Here is @matt's answer in Obj. WITH:

  NSMutableAttributedString *mas = [self.lab.attributedText mutableCopy];
  [mas replaceCharactersInRange:NSMakeRange(0, [mas.string length]) 
    withString:@"Little poltergeists make up the principle form of material manifestation"]; 
  self.lab.attributedText = mas;

Hope this helps someone!

+1
source

Swift 3 Just copy and execute this code to see the result

let label = UILabel()
let stringValue = "UILabel\nLine\nSpacing"
let attrString = NSMutableAttributedString(string: stringValue)
var style = NSMutableParagraphStyle()
style.lineSpacing = 24 // change line spacing between paragraph like 36 or 48
style.minimumLineHeight = 20 // change line spacing between each line like 30 or 40
attrString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSRange(location: 0, length: stringValue.characters.count))
label.attributedText = attrString
0
source

Source: https://habr.com/ru/post/1589324/


All Articles