Greg Rami
07/12/2023, 6:20 PMUIKitView
, I'm struggling to understand how to call setAttributedPlaceholder
with the right parameters. Here's what I have so far:
UIKitView(
background = Color.White,
factory = {
val textField = object : UITextField(CGRectMake(0.0, 0.0, 0.0, 0.0)) {
@ObjCAction
fun editingChanged() {
onValueChange(text?.cleanInput() ?: "")
}
}
val nsAttributedString = NSMutableAttributedString() <- how do I configure this, especially set the text
textField.setAttributedPlaceholder(nsAttributedString)
}
)
I can create an NSMutableAttributedString
and then call
addAttribute(
name = "foregroundColor",
value = UIColor.redColor,
range = NSMakeRange(0, 1)
)
on it. But how do I set the text of the placeholder? The NSAttributedString
and NSMutableAttributedString
constructors only take NSCoder
as an argument 😕ribesg
07/13/2023, 9:04 AM@Suppress("UNCHECKED_CAST")
inline fun NSAttributedString.Companion.create(
text: String,
vararg attributes: Pair<NSAttributedStringKey, Any>
): NSAttributedString =
NSAttributedString.create(
text,
attributes.toMap() as Map<Any?, *>
)
inline fun NSAttributedString.Companion.of(
vararg strings: NSAttributedString
): NSAttributedString =
NSMutableAttributedString.create("").apply {
strings.forEach(::appendAttributedString)
}
ribesg
07/13/2023, 9:06 AMuiView.statusLabel.attributedText = NSAttributedString.of(
NSAttributedString.create("Status: "),
NSAttributedString.create(status, NSForegroundColorAttributeName to UIColor.redColor)
)
ribesg
07/13/2023, 9:08 AM.create(…)
functionsGreg Rami
07/13/2023, 6:12 PM