레이블이 있고 속성이 지정된 문자열을 추가했습니다. 문자열은 내가 텍스트의 시작 부분에 *
를 추가하기 위해 노력하고있어이 텍스트에서 줄 수가 0이고 높이 제한이 없어도 내 레이블이 잘리는 이유는 무엇입니까?
let nameText = "My name is Shreesha and Im an iOS developer. My name is Shreesha and Im an iOS developer."`My name is Shreesha and Im an iOS developer. My name is Shreesha and Im an iOS developer.`
그래서 나는 기인 문자열을 사용하고 코드는
func attributedTextForFeeApplies() -> NSAttributedString {
let attributedText = NSMutableAttributedString(string: "* " + nameText)
attributedText.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.blue, range: NSMakeRange(0, attributedText.length))
attributedText.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 10), range: NSMakeRange(0, attributedText.length))
let superScriptString = "* "
attributedText.addAttribute(NSAttributedStringKey.baselineOffset, value: 2, range: NSMakeRange(0, superScriptString.characters.count))
attributedText.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 9), range: NSMakeRange(0, superScriptString.characters.count))
attributedText.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.blue, range: NSMakeRange(0, superScriptString.characters.count))
let superscriptAttributedString = attributedText
let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byTruncatingTail
superscriptAttributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraph, range: NSMakeRange(0, superscriptAttributedString.length))
return superscriptAttributedString
}
내가 준 다음과 같습니다이다 내가 0
없이 헤이로 라인의 수를 설정하더라도이 같은 레이블에 제약
하지만 코드가이 같은 벌금을하고있다 attributedText.addAttribute(NSAttributedStringKey.baselineOffset, value: 2, range: NSMakeRange(0, superScriptString.characters.count))
이 라인을 사용하지 않는 경우,
*
을 추가하는 경우 그것은 잘 작동하지만 텍스트의 시작 부분에 사용하는 경우 그냥 작동하지 않습니다 (
attributedText.addAttribute(NSAttributedStringKey.baselineOffset, value: 2, range: NSMakeRange(0, superScriptString.characters.count))
를 제거하지 않고) 중간
스크린 샷 :
그리고 글꼴 크기를 늘리면 작동합니다.
나는 NSAttributedString
에 문제가 있다고 생각하는데, 그렇지 않다면 나는 무엇이 문제인지 알고 싶다. 누군가 나를 도와주세요.
beacuse는 superscriptAttributedString = attributedText 가합시다 단락 NSMutableParagraphStyle =() = paragraph.lineBreakMode .byTruncatingTail superscriptAttributedString.addAttribute (NSAttributedStringKey.paragraphStyle, 값 : 단락 범위 : NSMakeRange (0 superscriptAttributedString.length)) 당신의 lable은 줄 수에 넣을 수 있습니다. –
나는 당신이 말한 것을 얻지 못했습니다 (당신의 lable은 줄 수에 넣을 수 있습니까?). 좀 더 자세히 설명해 주시겠습니까? –
NSMutableParagraphStyle은 한 줄을 여러 줄로 변환한다는 것을 의미하므로 텍스트 한 줄만 쓰려면 NSMutableParagraphStyle을 사용하지 마십시오. –