は、だから私は、この使用して迅速かつXcodeのようなものを作りたいです。私が考えているのは、UILabelを作成し、forループを作成して配列全体を反復し、各反復でlabel \ u {2022} + contentに追加することです。私は\ u {2022}がユニコードのドット点であることを知っていますが、問題は、リストを2つの列に分割して点の色を黄色にする方法が必要だということです。これは既定の色が黒であるため、上記のようにプログラムでドットを追加するとできません。ドットの数が配列の内容から変化すると、たとえば配列のサイズが3の場合、3ドットだけが左に2つ、右に1つ表示されます。この要件を満たす方法が必要です。 2つのテーブルビューで画面の半分を占め、この要素を配列に応じて各テーブルビューに追加します。ここでのベストプラクティスは何か、または配列に依存する形式でストーリーボードにこれを作成する方法があります。Swiftで弾丸を作る方法は?私は、アレイからの各ドットを得る</p> <p><a href="https://i.stack.imgur.com/gTnXC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gTnXC.png" alt="enter image description here"></a></p> <p>:
3
A
答えて
5
2つのラベルを列のビュー内で使用します。両方のラベルが
class Helper {
static func bulletedList(strings:[String], textColor:UIColor, font:UIFont, bulletColor:UIColor, bulletSize:BulletSize) -> NSAttributedString {
let textAttributesDictionary = [NSFontAttributeName : font, NSForegroundColorAttributeName:textColor]
let bulletAttributesDictionary = [NSFontAttributeName : font.withSize(bulletSize.rawValue), NSForegroundColorAttributeName:bulletColor]
let fullAttributedString = NSMutableAttributedString.init()
for string: String in strings
{
let bulletPoint: String = "\u{2022}"
let formattedString: String = "\(bulletPoint) \(string)\n"
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: formattedString)
let paragraphStyle = createParagraphAttribute()
attributedString.addAttributes([NSParagraphStyleAttributeName: paragraphStyle], range: NSMakeRange(0, attributedString.length))
attributedString.addAttributes(textAttributesDictionary, range: NSMakeRange(0, attributedString.length))
let string:NSString = NSString(string: formattedString)
let rangeForBullet:NSRange = string.range(of: bulletPoint)
attributedString.addAttributes(bulletAttributesDictionary, range: rangeForBullet)
fullAttributedString.append(attributedString)
}
return fullAttributedString
}
static func createParagraphAttribute() -> NSParagraphStyle {
var paragraphStyle: NSMutableParagraphStyle
paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.tabStops = [NSTextTab(textAlignment: .left, location: 15, options: NSDictionary() as! [String : AnyObject])]
paragraphStyle.defaultTabInterval = 15
paragraphStyle.firstLineHeadIndent = 0
paragraphStyle.lineSpacing = 3
paragraphStyle.headIndent = 10
return paragraphStyle
}
}
をmultulinedし、単に次のように動作しますスウィフトTABSTOPで
0
ラベルの属性付きテキストとしてあなたbullettedリストを作成するHelper.bulletedList
を使用して変更されている
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 0 // 0 means unlimited
paragraphStyle.maximumLineHeight = 0
paragraphStyle.firstLineHeadIndent = 30
paragraphStyle.headIndent = 0
paragraphStyle.tabStops = [NSTextTab(textAlignment: .left, location: 15, options: Dictionary<NSTextTab.OptionKey, Any>())]
paragraphStyle.defaultTabInterval = 10 //changing defaultTabInterval changes the distance between black dot & text
paragraphStyle.lineSpacing = 5
スウィフト4については
0
、あなたは、このクラスを使用することができます。
class NSAttributedStringHelper {
static func createBulletedList(fromStringArray strings: [String], font: UIFont? = nil) -> NSAttributedString {
let fullAttributedString = NSMutableAttributedString()
let attributesDictionary: [NSAttributedStringKey: Any]
if font != nil {
attributesDictionary = [NSAttributedStringKey.font: font!]
} else {
attributesDictionary = [NSAttributedStringKey: Any]()
}
for index in 0..<strings.count {
let bulletPoint: String = "\u{2022}"
var formattedString: String = "\(bulletPoint) \(strings[index])"
if index < strings.count - 1 {
formattedString = "\(formattedString)\n"
}
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: formattedString, attributes: attributesDictionary)
let paragraphStyle = NSAttributedStringHelper.createParagraphAttribute()
attributedString.addAttributes([NSAttributedStringKey.paragraphStyle: paragraphStyle], range: NSMakeRange(0, attributedString.length))
fullAttributedString.append(attributedString)
}
return fullAttributedString
}
private static func createParagraphAttribute() -> NSParagraphStyle {
let paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.tabStops = [NSTextTab(textAlignment: .left, location: 15, options: NSDictionary() as! [NSTextTab.OptionKey : Any])]
paragraphStyle.defaultTabInterval = 15
paragraphStyle.firstLineHeadIndent = 0
paragraphStyle.headIndent = 11
return paragraphStyle
}
}
これを使用するには:
let stringArray = ["first row", "second row", "third row"]
label.attributedText = NSAttributedStringHelper.createBulletedList(fromStringArray: stringArray, font: UIFont.systemFont(ofSize: 15))
関連する問題
- 1. jQueryのFlot.js:</p> <p><a href="https://i.stack.imgur.com/DdqPc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DdqPc.png" alt="enter image description here"></a></p> <p>:
- 2. <p><a href="https://i.stack.imgur.com/t7N5M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t7N5M.png" alt="enter image description here"></a></p>
- 3. は、私がこの</p> <p><img src="https://i.stack.imgur.com/r8u5k.png" alt="enter image description here"></p> <p>で</p> <p><img src="https://i.stack.imgur.com/P6FpH.png" alt="enter image description here"></p> <p>を交換したいのJava Swingの
- 4. 丸い楕円形のボタンを作成するには?ボタンの周りに黒い縁マイナス</p> <p><a href="https://i.stack.imgur.com/8iEHT.png" rel="nofollow"><img src="https://i.stack.imgur.com/8iEHT.png" alt="enter image description here"></a></p> <p>:
- 5. 行の全体的な価値を計算する方法は?私は</p> <p><a href="https://i.stack.imgur.com/cDfAL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cDfAL.png" alt="enter image description here"></a></p> <p>をしたい
- 6. CMS <a href="https://i.stack.imgur.com/Lvr4C.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lvr4C.jpg" alt="enter image description here"></a>から管理CMS
- 7. 注文は別の表から、私は様々なユーザー</p> <p><a href="https://i.stack.imgur.com/5AwOC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5AwOC.png" alt="enter image description here"></a></p> <p>以下のようなスキルテーブルを持っている
- 8. はHG、これは私がフォルダVirtualDlls下のすべての.dllファイルを除外したい</p> <p><a href="https://i.stack.imgur.com/UbSlW.png" rel="nofollow"><img src="https://i.stack.imgur.com/UbSlW.png" alt="enter image description here"></a></p> <p>作業するフォルダ
- 9. WPF RichTextBoxの幅を親コントロールの幅に従う方法は?</p> <p><a href="https://i.stack.imgur.com/UXquc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UXquc.png" alt="enter image description here"></a></p> <p>上部は以下、DataGridのあるテキストボックスです:
- 10. エラー私は</p> <p></p> <p><a href="https://i.stack.imgur.com/aIxqc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIxqc.jpg" alt="enter image description here"></a>エラーを作成発生かみそりMVCプロジェクトを作成しようとしています
- 11. 機能の画像:私はラインを構成する点(x、y)のリストを取得したい</p> <p><a href="https://i.stack.imgur.com/qKAk5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qKAk5.png" alt="enter image description here"></a></p> <p>:パイソン
- 12. これまでのところ、次の私はD3</p> <p><a href="https://i.stack.imgur.com/j8xLX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j8xLX.jpg" alt="enter image description here"></a></p> <p>で、次の再作成しようとしている
- 13. RecyclerView.OnScrollListenerは()に影響を与え、なぜ私は私のアプリ</p> <p><a href="https://i.stack.imgur.com/fRaTl.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fRaTl.gif" alt="enter image description here"></a></p> <p>でこの機能を持ちたいrecyclerview
- 14. recyclerviewのビューの幅を他のビューに依存させる方法は? 、インナーをここで</p> <p><a href="https://i.stack.imgur.com/idDVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/idDVU.png" alt="enter image description here"></a></p> <p>:
- 15. オラクル:</p> <p><a href="https://i.stack.imgur.com/qLgCR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qLgCR.png" alt="enter image description here"></a></p> <p>列Aは、私たちが参加かかりますどの列です:別のテーブル
- 16. これは私のリレーショナル・スキーマのすべての販売注文から</p> <p><a href="https://i.stack.imgur.com/FG7fD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FG7fD.png" alt="enter image description here"></a></p> <p>ある単一の注文
- 17. は私のFirebaseデータベースはここでは、この</p> <p><a href="https://i.stack.imgur.com/pnh6l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pnh6l.png" alt="enter image description here"></a></p> <p>のように見えるスウィフト
- 18. 私はContactUsPageSettingsの下で私のCMS</p> <p><a href="https://i.stack.imgur.com/W5fkN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W5fkN.png" alt="enter image description here"></a></p> <p>で次のように設定しているリスト
- 19. のiOS:私は青色のビューコントローラをロードボタンをIをクリックすると</p> <p><a href="https://i.stack.imgur.com/f1lts.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f1lts.png" alt="enter image description here"></a></p> <p>:ナビゲーションバーは、メインビューコントローラ
- 20. は、私は次のようなエラーDBconfig.phpへ</p> <p><a href="https://i.stack.imgur.com/ULTWg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ULTWg.png" alt="enter image description here"></a></p> <p>リンクを取得していますエラーPDO/SQL
- 21. 私は</p> <p><a href="https://i.stack.imgur.com/jhTxN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jhTxN.jpg" alt="enter image description here"></a></p> <p>以下に類似し、その端部にマーカーでSSRSで棒グラフを作成したいマーカー
- 22. パイソン:NameError「」は今...</p> <p><a href="https://i.stack.imgur.com/tryyh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tryyh.png" alt="Desired output"></a></p> <p>を
- 23. 私が欲しいもの</p> <p><a href="https://i.stack.imgur.com/8TH6m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8TH6m.png" alt="enter image description here"></a></p> <p>以下のように私は、グラフのネットワークを持っているCYPHER(のNeo4j)
- 24. 私はこのイメージが閾値関数の出力である画像</p> <p><a href="https://i.stack.imgur.com/UKTJw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UKTJw.jpg" alt="enter image description here"></a></p> <p>を有する手
- 25. は、私はこの</p> <p><a href="https://i.stack.imgur.com/CwfjQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CwfjQ.png" alt="enter image description here"></a></p> <p>のようなチャットのためのテーブルを持っている
- 26. 2にアンドロイドスタジオ1をアップグレードした後、私は <p><a href="https://i.stack.imgur.com/AqxlY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AqxlY.png" alt="enter image description here"></a></p> <h1>Androidのスタジオ版</h1>を取得
- 27. クリップボックスシャドウは、方法はあり現在鉱山が</p> <p><a href="https://i.stack.imgur.com/xDug1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xDug1.png" alt="enter image description here"></a></p> <p>下の画像のように見える
- 28. 多次元NSArrayからNSArrayへ?私は9つの要素が含まれていたNSArrayを持って</p> <p><a href="https://i.stack.imgur.com/vAznr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vAznr.png" alt="enter image description here"></a></p> <p>:
- 29. は、私はマーケティングが許可されている顧客を返す必要が</p> <p><a href="https://i.stack.imgur.com/kmPAt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kmPAt.png" alt="enter image description here"></a></p> <p>(スクリーンショットを参照)、ビット値= 1
- 30. キーボード言語の検出方法は?以下のJava言語で(NetBeansの)GUI、</p> <p><a href="https://i.stack.imgur.com/tQGP5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tQGP5.png" alt="enter image description here"></a></p> <p>については
はチュートリアル[ここ](https://www.raywenderlich.com/4147/core-text-tutorial-for-ios-making-a-magazine-appを参照し、そのためにCoreTextを使用する必要があります) – Tj3n
あなたはUICollectionViewを見ましたか?私はそれ自身をあまり使用していませんが、これはこのための完全な使用例のように見えます。 –
本当に知っておきたいのは、2つの列にテキストを描画する方法であり、箇条書きの部分はちょうど赤いニシンですよね? – matt