iosswiftiqkeyboardmanager

problem with attributed text for keyboard titleBarButton when using IQKeyBoardManager


I am using IQKeyboardManager with Swift. I have added a cancel button on my datepicker. Everything is working, but I am having trouble with the attributed text for the cancel button not taking effect. What am I doing wrong? Here is a code fragment

cell.field.attributedPlaceholder = NSAttributedString(string: "Cancel",
            attributes: [.foregroundColor: UIColor.black,
               .font: UIFont.boldSystemFont(ofSize: 12)])

cell.field.keyboardToolbar.titleBarButton.setTarget(self,
        action:#selector(datePickerWasCanceled(sender:)))

Here is a sample screen shot of current results -- I would have thought the cancel should be in black and bold.

keyboard cancel button does not have specified attributes


Solution

  • cell.field.attributedPlaceholder = NSAttributedString(string: "Cancel") cell.field.keyboardToolbar.titleBarButton.titleFont = UIFont.boldSystemFont(ofSize: 17.0) cell.field.keyboardToolbar.titleBarButton.selectableTitleColor = UIColor.black

    cell.field.keyboardToolbar.titleBarButton.setTarget(self, action:#selector(datePickerDidCancel(sender:))