MessageViewController: Inconsistent text view font

The latest release, 0.2.0, is causing the font to change in the text view as I type. Also introducing the left button has caused some really strange layout issues. For example, if I set showsLeftButton to false, the insets are rendered completely off center.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 20 (9 by maintainers)

Most upvoted comments

@rnystrom I’ll work on that upcoming weekend.

@rnystrom Never mind, my bad. I was thinking the same code was used in the example but that works fine.

I did find the problem, the textview uses an attributed string and uses different font sizes. The first character is the correct font but all the other after that use pointSize 17.0. If I input a simple text: Jj and print the attributes we can see the difference between the 2 letters. The reason why is unclear to me yet. Any suggestions?

attributes >> Optional(J{
    NSFont = "<UICTFont: 0x7fa416c1f850> font-family: \".SFUIText\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
}j{
    NSFont = "<UICTFont: 0x7fa416c17de0> font-family: \".SFUIText\"; font-weight: normal; font-style: normal; font-size: 17.00pt";
    "com.messageviewcontroller.autocompletekey" = 0;
})

@AndrewBarba I had the same problem. You can fix this by settings your inset before your settings the left- and right button properties.

// Set messageView inset
messageView.inset = UIEdgeInsets(top: 20, left: 8, bottom: 20, right: 16)
messageView.font = UIFont.preferredFont(forTextStyle: .body)

// Right button
messageView.setButton(title: "Send".uppercased(), for: .normal, position: .right)
messageView.setButton(font: UIFont.systemFont(ofSize: 14), position: .right)
messageView.addButton(target: self, action: #selector(onRightButton), position: .right)
messageView.rightButtonTint = .blue

If you set the inset afterwards you get weird behaviour indeed because the calculation rely on the insets.

@rnystrom I’m still seeing really strange layout and font issues on 0.2.1.

On load:

screen shot 2018-03-17 at 12 33 04 pm

After typing:

screen shot 2018-03-17 at 12 33 14 pm

And here’s my config:

        // Setup the button using text or an icon
        messageView.showLeftButton = false

        // Right button
        messageView.setButton(title: "Send".uppercased(), for: .normal, position: .right)
        messageView.setButton(font: UIFont(barstool: .branding, size: 14), position: .right)
        messageView.addButton(target: self, action: #selector(handleSendButtonTapped), position: .right)
        messageView.rightButtonTint = .barstoolBrightBlue

        // Change the appearance of the text view and its content
        messageView.font = UIFont(barstool: .branding, size: 14)
        messageView.textView.font = UIFont(barstool: .regular, size: 14)
        messageView.textView.placeholderText = "Type comment..."
        messageView.textView.placeholderTextColor = .lightGray
        messageView.textView.tintColor = .barstoolBrightBlue
        messageView.applyBorder(.top, color: .separator, size: 0.5)
        messageView.inset = UIEdgeInsets(top: 20, left: 16, bottom: 20, right: 16)

        // Capsule view
        let containerView = UIView()
        containerView.backgroundColor = UIColor(red: 0.945, green: 0.945, blue: 0.945, alpha: 1)
        containerView.borderColor = .separator
        containerView.borderWidth = 1
        containerView.cornerRadius = 3

        messageView.insertSubview(containerView, at: 0)
        containerView.snp.makeConstraints {
            $0.top.equalToSuperview().inset(8)
            $0.leading.equalToSuperview().inset(8)
            $0.trailing.equalToSuperview().inset(8)
            if #available(iOS 11, *) {
                $0.bottom.equalTo(messageView.safeAreaLayoutGuide.snp.bottom).inset(8)
            } else {
                $0.bottom.equalToSuperview().inset(8)
            }
        }

Yup makes sense. While you’re fixing that, any chance you can decouple the font property from setting the font for text view and all buttons? I’d prefer to set the fonts individually