nathantannar4 / InputBarAccessoryView

A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
MIT License
1.15k stars 229 forks source link

Autocomplete with custom UITextView changes it's style (font, alignment etc.) #231

Closed shadzik closed 2 years ago

shadzik commented 2 years ago

Hey,

is it possible to show autocomplete suggestions from a custom textView, not the inputTextView, without the autocomplete manager changing the style of the textView?

My code looks like this:

lazy var autocompleteManager: AutocompleteManager = { [unowned self] in
        let manager = AutocompleteManager(for: self.textView)
        manager.delegate = self
        manager.dataSource = self
        manager.tableView.registerReusableCell(MentionHashtagTableViewCell.self)
        manager.tableView.rowHeight = 60
        return manager
    }()

But when typing @ or # the style of the font configured in self.textView changes i.e. the font gets smaller, text alignment changes to left etc.

Would be great if the textView style wouldn't change.

Thanks for your suggestions!

shadzik commented 2 years ago

Got it partially working through the defaultTextAttributes property:

let font = UIFont.systemFont(ofSize: 33, weight: .heavy)
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.alignment = .center
        let attributes: [NSAttributedString.Key: Any] = [
            .font: font,
            .foregroundColor: UIColor.white,
            .paragraphStyle: paragraphStyle
        ]

        autocompleteManager.defaultTextAttributes = attributes

But paragraphStyle is stil wrong and is private. So maybe i'll create a PR that adds the possibility to pass your own paragraph style

shadzik commented 2 years ago

Ok, for those who are interested:

autocompleteManager.paragraphStyle.alignment = .center

Did the trick for me