Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showing incorrectly when use lineSpacing #350

Open
mlight3 opened this issue Nov 19, 2018 · 0 comments
Open

showing incorrectly when use lineSpacing #350

mlight3 opened this issue Nov 19, 2018 · 0 comments

Comments

@mlight3
Copy link

mlight3 commented Nov 19, 2018

class V3: UIViewController {
    let labelWithBonMot = UILabel()
    let label = UILabel()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        labelWithBonMot.numberOfLines = 2
        label.numberOfLines = 2
        
        view.addSubview(labelWithBonMot)
        view.addSubview(label)
        
        labelWithBonMot.snp.makeConstraints {
            $0.top.equalToSuperview().offset(30)
            $0.left.right.equalToSuperview()
        }
        
        label.snp.makeConstraints {
            $0.left.right.equalToSuperview()
            $0.top.equalTo(labelWithBonMot.snp.bottom).offset(30)
        }
        

        ///////////////////////////////////

        let text = "聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖\n聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖聖"
        let contentStyle = StringStyle([.font(UIFont(name: "HiraginoSans-W3", size: 13)!),
                                        .tracking(.point(-0.3)),
                                        .lineSpacing(7),
                                        .lineBreakMode(.byTruncatingTail)])
        
        labelWithBonMot.attributedText = text.styled(with: contentStyle)
        
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineBreakMode = .byTruncatingTail
        paragraphStyle.lineSpacing = 7
        let attributes: [NSAttributedString.Key: Any] = [
            .font: Fonts.HiraginoSans.w3.size(13),
            .kern: -0.3,
            .paragraphStyle: paragraphStyle
        ]
        
        label.attributedText = NSAttributedString(string: text, attributes: attributes)
    }
}

Here is my code.
It shows like this.
simulator screen shot - iphone 8 - 2018-11-19 at 12 56 55

labelWithBonMot is not showing correct lineSpacing.

Here is a attributes what I've got in console

====  contentStyle.attributes  ====
[__C.NSAttributedStringKey(_rawValue: NSParagraphStyle): Alignment 4, LineSpacing 7, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (
    28L,
    56L,
    84L,
    112L,
    140L,
    168L,
    196L,
    224L,
    252L,
    280L,
    308L,
    336L
), DefaultTabInterval 0, Blocks (
), Lists (
), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0, __C.NSAttributedStringKey(_rawValue: BonMotTransformations): [[:]], __C.NSAttributedStringKey(_rawValue: NSKern): -0.3, __C.NSAttributedStringKey(_rawValue: NSFont): <UICTFont: 0x7fa752d0c2e0> font-family: "HiraginoSans-W3"; font-weight: normal; font-style: normal; font-size: 13.00pt]




====  native attributes  ====
[__C.NSAttributedStringKey(_rawValue: NSFont): <UICTFont: 0x7fa752d0c2e0> font-family: "HiraginoSans-W3"; font-weight: normal; font-style: normal; font-size: 13.00pt, __C.NSAttributedStringKey(_rawValue: NSKern): -0.3, __C.NSAttributedStringKey(_rawValue: NSParagraphStyle): Alignment 4, LineSpacing 7, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (
    28L,
    56L,
    84L,
    112L,
    140L,
    168L,
    196L,
    224L,
    252L,
    280L,
    308L,
    336L
), DefaultTabInterval 0, Blocks (
), Lists (
), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant