UILabel
में बुलेट बिंदु दिखाने के लिए प्रारूप करना संभव है?बुलेट पॉइंट्स के साथ UILabel प्रारूपित करें?
यदि हां, तो मैं इसे कैसे कर सकता हूं?
UILabel
में बुलेट बिंदु दिखाने के लिए प्रारूप करना संभव है?बुलेट पॉइंट्स के साथ UILabel प्रारूपित करें?
यदि हां, तो मैं इसे कैसे कर सकता हूं?
शायद आपकी स्ट्रिंग में बुलेट वर्ण के लिए यूनिकोड कोड बिंदु का उपयोग करें?
ऑब्जेक्टिव-सी
myLabel.text = @"\u2022 This is a list item!";
स्विफ्ट 4
myLabel.text = "\u{2022} This is a list item!"
मैं गोलियों के लिए 'UITextField' का भी उपयोग करूंगा क्योंकि 'उइलाबेल' और अधिक कठिन होने जा रहा है। – Andrew
@Andrew एक UILabel क्यों अच्छा नहीं है ??? – daveMac
@ डेवमैक 'उइलाबेल आमतौर पर टेक्स्ट की एक पंक्ति के साथ उपयोग करने में सबसे आसान है।जब आप पाठ के लंबे/बड़े ब्लॉक (जिस तरह से गोलियों को स्वरूपित किया जाता है) प्राप्त होता है, तो – Andrew
सिर्फ जोड़ने "•"
यहां तक कि मैं अपने TextView के लिए कुछ इस तरह के लिए देख रहा था। मैंने जो किया, बस मेरी स्ट्रिंग के साथ स्ट्रिंग के ऊपर संलग्न करें और इसे मेरे टेक्स्ट व्यू पर पास करें, लेबल के लिए भी किया जा सकता है। मैंने भविष्य के दर्शक के लिए इसका उत्तर दिया।
• मेरे लिए काम किया। मेरे पास * एक्सकोड में मैंने प्रतिलिपि बनाकर प्रतिस्थापित किया है • और यह मेरे लेबल I के लिए ठीक है "लेबल" के साथ ठीक काम करता है • – Brian
में इस लिंक तेज 3,1
lblItemName.text = "\u{2022} This is a list item!"
चेक बाहर, मैं सूची आइटम प्रतीक के रूप में एक कस्टम दृश्य बुलेट बिंदुओं/अन्य प्रतीक/छवि के साथ टेक्स्ट को फ़ॉर्मेट करने (UILabel की attributeText संपत्ति का उपयोग कर) (स्विफ्ट 3.0) बनाया https://github.com/akshaykumarboth/SymbolTextLabel-iOS-Swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var symbolView: SymbolTextLabel!
var testString = "Understanding the concept of sales"
var bulletSymbol = "\u{2022}"
var fontsize: CGFloat= 18
override func viewDidLoad() {
super.viewDidLoad()
//First way // Dynamically creating SymbolTextLabel object
let symbolTextLabel = SymbolTextLabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
symbolTextLabel.setText(text: testString, symbolCode: bulletSymbol) //setting text and symbol of text item
symbolTextLabel.setFontSize(textSize: fontsize) // setting font size
//symbolTextLabel.setSpacing(spacing: 5) // setting space between symbol and text
self.view.addSubview(symbolTextLabel)
//second way // from storyboard or interface builder
symbolView.setText(text: testString, symbolCode: bulletSymbol)
//setting text and symbol of text item
symbolView.setFontSize(textSize: fontsize) // setting font size
//symbolView.setSpacing(spacing: 5) // setting space between symbol and text
}
}
यहाँ स्विफ्ट
साथlet label = UILabel()
label.frame = CGRect(x: 40, y: 100, width: 280, height: 600)
label.textColor = UIColor.lightGray
label.numberOfLines = 0
let arrayString = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
]
label.attributedText = add(stringList: arrayString, font: label.font, bullet: "")
self.view.addSubview(label)
अच्छा समाधान है 10
जोड़े गोली विशेषताओं
func add(stringList: [String],
font: UIFont,
bullet: String = "\u{2022}",
indentation: CGFloat = 20,
lineSpacing: CGFloat = 2,
paragraphSpacing: CGFloat = 12,
textColor: UIColor = .gray,
bulletColor: UIColor = .red) -> NSAttributedString {
let textAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: textColor]
let bulletAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: bulletColor]
let paragraphStyle = NSMutableParagraphStyle()
let nonOptions = [NSTextTab.OptionKey: Any]()
paragraphStyle.tabStops = [
NSTextTab(textAlignment: .left, location: indentation, options: nonOptions)]
paragraphStyle.defaultTabInterval = indentation
//paragraphStyle.firstLineHeadIndent = 0
//paragraphStyle.headIndent = 20
//paragraphStyle.tailIndent = 1
paragraphStyle.lineSpacing = lineSpacing
paragraphStyle.paragraphSpacing = paragraphSpacing
paragraphStyle.headIndent = indentation
let bulletList = NSMutableAttributedString()
for string in stringList {
let formattedString = "\(bullet)\t\(string)\n"
let attributedString = NSMutableAttributedString(string: formattedString)
attributedString.addAttributes(
[NSAttributedStringKey.paragraphStyle : paragraphStyle],
range: NSMakeRange(0, attributedString.length))
attributedString.addAttributes(
textAttributes,
range: NSMakeRange(0, attributedString.length))
let string:NSString = NSString(string: formattedString)
let rangeForBullet:NSRange = string.range(of: bullet)
attributedString.addAttributes(bulletAttributes, range: rangeForBullet)
bulletList.append(attributedString)
}
return bulletList
}
यहाँ परिणाम है:
में स्विफ्ट 4 मैं का इस्तेमाल किया है नई लाइन के साथ "•"
@IBOutlet weak var bulletLabel: UILabel!
let arrayOfLines = ["Eat egg for protein","You should Eat Ghee","Wheat is with high fiber","Avoid to eat Fish "]
for value in arrayOfLines {
bulletLabel.text = bulletLabel.text! + " • " + value + "\n"
}
आउटपुट:
अनॉर्डर्ड सूची टैग (यानी।
- UILabel
- ...
, आप यह कर सकते हैं। – Hoque@ होक: 'उइलाबेल अपने पाठ को HTML के रूप में नहीं मानता है। –
इसके लिए यहां एक कक्षा है! https://codeload.github.com/eyalc/ECListView/zip/master – Hemang