0
2種類のテキストアラインメントを持つattributedTextを使用して、いくつかのテキストをUILabelに表示しようとしています。 Firebase &から値を取得していますが、それらはキーと値の型です。何らかの理由で、私はタイトルを左に揃え、字幕を右に並べることはできません。どんな助けもありがとうございます。NSAttributedStringは2種類のテキストアラインメントを持っています
private func descriptionAttributedText() -> NSAttributedString {
let title = "some title on the left side of the screen"
let subtitle = "subtitle on the right side"
let rightParagraph = NSMutableParagraphStyle()
rightParagraph.alignment = .right
let titleAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14), NSAttributedStringKey.foregroundColor: UIColor.black]
let titleString = NSMutableAttributedString(string: title, attributes: titleAttributes)
let subtitleAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 13), NSAttributedStringKey.foregroundColor: UIColor.darkGray, NSAttributedStringKey.paragraphStyle: rightParagraph]
let subtitleString = NSAttributedString(string: subtitle, attributes: subtitleAttributes)
let paragraph = NSMutableParagraphStyle()
paragraph.setParagraphStyle(.default)
paragraph.lineSpacing = 2
let range = NSMakeRange(0, titleString.string.count)
titleString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraph, range: range)
titleString.append(subtitleString)
return titleString
}
私は取得しています結果はタイプ「Titlesubtitle」
私はここで見てきた、Attributed text with two text alignmentsのですが、それは非常に私を助けていません。
私はApp Storeで同じ効果を取得しようとしているが、代わりの
出品者..................... Facebookの株式会社よ。、私は
SellerFacebook株式会社
なぜ彼らは整列していないと言いますか?あなたが得るものを投稿するかもしれませんか? –
質問を編集しました。 – r3dm4n
私は、(NSAttributedString')そのように問題を解決することはできません参照してください。この図では、2つの異なるUILabelを持つ 'UITableViewCell'(最初のものについて話しています)を持つ' UITableView'(おそらくカスタム 'UIVIew'かもしれません)があります。 –