shunsuke_stackoverflow
shunsuke_stackoverflow

Reputation: 467

Why does single line text have new line?

I have been using attributed text for UILabel of UITableViewCell. Sometimes,even if text is single line but, text has new line.

My code is here

if notnullCheck(catchcopy){

                //行間
                let attributedText = NSMutableAttributedString(string: catchcopy!)
                let paragraphStyle = NSMutableParagraphStyle()
                paragraphStyle.lineSpacing = 5
                attributedText.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedText.length))

                self.catchcopyLabel.attributedText = attributedText


            }
            self.catchcopyLabel.sizeToFit()

The text height is 33 when multi line text is. The text height is 14 when single line text is. But sometimes, the text height is 19 when single line text is. when line height is 19,the text has new line.

What is this problem?

The following text is debug log.

(98.0, 14.0)
勤務地表記確認

(230.0, 19.0)
ケイサイカキンなしんこうぃあ 02

Both texts are also single line.But height is not same. enter image description here

Upvotes: 0

Views: 181

Answers (1)

Satachito
Satachito

Reputation: 5888

Assuming you are using 'HiraKakuProN-W6' font and its size is 14.

It's not a matter of new line but of Japanese space character(全角スペース).

If you delete Japanese space character, you will get height of 14.

I have encountered this kind of strangeness since many years ago,

so I think it's BUG of HiraXXXXX-XX font.

Upvotes: 1

Related Questions