में लाइन के अंत में स्थान NSKernAttributeName
का उपयोग करते समय यह प्रत्येक पंक्ति के अंत में एक स्थान डालता है, क्या इसे ठीक करने का कोई तरीका है? मैं इस श्रेणी मेंNSKernAttributeName स्थान एनएसएट्रिब्यूटेड स्ट्रिंग
NSRange(location: 0, length: self.text!.characters.count-1)
लेकिन मैं इसे प्रत्येक पंक्ति के लिए सेट नहीं करना चाहता हूं।
आप में से प्रत्येक के अंत में रिक्त स्थान देख सकते हैं:
यह मैं
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
var text = "Hello, playground\nhow are you?"
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.paragraphSpacing = 50
paragraphStyle.alignment = NSTextAlignment.Left
paragraphStyle.lineBreakMode = NSLineBreakMode.ByTruncatingTail
let attributes = [
NSParagraphStyleAttributeName: paragraphStyle
, NSKernAttributeName: 20
]
let attributedString = NSAttributedString(string: text, attributes: attributes)
let label = UILabel()
label.attributedText = attributedString
label.numberOfLines = 0
label.textColor = UIColor.greenColor()
label.backgroundColor = UIColor.orangeColor()
label.sizeToFit()
label.center = CGPoint(x: 500, y: 100)
var text2 = "What's up\nWhere are you?"
let attributedString2 = NSAttributedString(string: text2, attributes: attributes)
let label2 = UILabel()
label2.attributedText = attributedString2
label2.numberOfLines = 0
label2.textColor = UIColor.greenColor()
label2.backgroundColor = UIColor.orangeColor()
label2.sizeToFit()
label2.center = CGPoint(x: 500, y: 250)
var text3 = "Hello"
let attributedString3 = NSAttributedString(string: text3, attributes: attributes)
let label3 = UILabel()
label3.attributedText = attributedString3
label3.numberOfLines = 0
label3.textColor = UIColor.greenColor()
label3.backgroundColor = UIColor.orangeColor()
label3.sizeToFit()
label3.center = CGPoint(x: 500, y: 400)
let holderView = UIView(frame: CGRect(x: 0, y: 0, width: 1000, height: 500))
holderView.backgroundColor = UIColor.lightGrayColor()
holderView.addSubview(label)
holderView.addSubview(label2)
holderView.addSubview(label3)
XCPlaygroundPage.currentPage.liveView = holderView
परिणाम के साथ
उपयोग कर रहा हूँ एक खेल का मैदान में परीक्षण कोड इस तरह लग रही है रेखाएं।
यह does not उत्तर दिया गया बनाएं समस्या को हल करने के लिए प्रकट – richy