I’m still very confused.
Earlier you wrote:
I would like, if possible to generate a UIView for every time the sentence starts with "•" and nest it within it's own UIView.
Do you care about sentences? Or about lines? Sentences are a tricky linguistic concept and quite hard to parse out, so I’m going to assume you’re looking for lines. Let me know otherwise.
Today you wrote:
I just don't know how I would implement the logic where it would follow and action if it contains (or starts) with the symbol.
I’m having a hard time parsing that sentence. I’m going to presume that “follow and action” was meant to be “follow an action”.
Let’s try and make this more concrete, shall we? Here’s some code that walks the lines in a string looking for lines with a specific prefix:
let testString = """
This is some text:
• Bullet one
• Bullet two
• Bullet three
"""
testString.enumerateLines { (line, _) in
if line.hasPrefix("• ") {
print("+", line)
} else {
print("-", line)
}
}
Is that what you’re looking for? If not, please provide more details.
I just want to present each sentence beginning with a "•" in it's own
UIView
so I can style it.
A
UIView
by itself doesn’t display anything, so presumably you’re using a specific view to display this text. What sort of view is that? Our built-in text displaying views (
UILabel
and
UITextView
) handle attributed strings, so you don’t need multiple views to do styling. For example, if you want to style each bulleted line separately, you’d apply the style to an attributed string and then tell a
UITextView
to display that string.
Or do you want to use a custom view for that?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"