-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi,
I have gone through your code and this is wonderful code.
But you need to change the code little bit from this
for att in attr! {
if att.key == NSAttributedStringKey.foregroundColor {
if att.value as! UIColor == UIColor.systemBlue() {
setupBackspace(cursorPosition: cursorPosition-1, length: length+1)
return
} else {
length > 0 ? removeText(length: length+1) : removeText(length: 0)
return
}
} else {
length > 0 ? removeText(length: length+1) : removeText(length: 0)
return
}
}
To
if attr?.contains(where: {$0.key == NSAttributedStringKey.foregroundColor}) ?? false, let att
= attr?.filter({$0.key == NSAttributedStringKey.foregroundColor}){
if att[NSAttributedStringKey.foregroundColor] as! UIColor == UIColor.systemBlue() {
setupBackspace(cursorPosition: cursorPosition-1, length: length+1)
return
}else {
length > 0 ? removeText(length: length+1) : removeText(length: 0)
return
}
}else{
length > 0 ? removeText(length: length+1) : removeText(length: 0)
return
}
because this is not compulsory that the on the first index you get NSAttributedStringKey.foregroundColor every time.
So check it whether exists in the array or not.
Happy Coding ...
Thank You for the code
Metadata
Metadata
Assignees
Labels
No labels