Monday, June 15, 2026
HomeiOS Developmentios - Setting the enter container's constraints for my messaging app

ios – Setting the enter container’s constraints for my messaging app

[ad_1]

I am engaged on a typical messaging app and I am having issues getting the enter container view (view with “sort message” & ship butto) to stay to the underside of the display screen.

Within the chat controller, I declare an enter container variable with these constraints:

non-public lazy var customInputView: CustomInputAccessoryView = {
    let iv = CustomInputAccessoryView(body: CGRect(x: 0, y: 0, width: view.body.width, top: 50))
    return iv
}()

I set the x & y to 0, pondering that it could follow the underside to duplicate different messaging apps, however that is not working. As an alternative, It is solely displaying half of the container (container in purple):

enter image description here

Am I setting the constraints incorrectly? Right here is the code for the enter accent view. Any assist could be nice as I have been caught on this for weeks now

class CustomInputAccessoryView: UIView {

// MARK: VARIABLES ----
non-public let messageInputTextView: UITextView = {
    let television = UITextView()
    television.font = UIFont.systemFont(ofSize: 16)
    television.isScrollEnabled = false
    return television
}()

non-public lazy var sendButton: UIButton = {
    let button = UIButton(sort: .system)
    button.setTitle("Ship", for: .regular)
    button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
    button.setTitleColor(.systemPurple, for: .regular)
    button.addTarget(self, motion: #selector(handleSendMessage), for: .touchUpInside)
    return button
}()


override init(body: CGRect) {
    tremendous.init(body: body)
    
    backgroundColor = .purple
    autoresizingMask = .flexibleHeight

    addSubview(sendButton)
    sendButton.topAnchor.constraint(equalTo: topAnchor).isActive = true
    sendButton.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
    sendButton.titleEdgeInsets.prime = 4
    sendButton.titleEdgeInsets.proper = 8
    
    addSubview(messageInputTextView)
    messageInputTextView.topAnchor.constraint(equalTo: topAnchor).isActive = true
    messageInputTextView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
    messageInputTextView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor).isActive = true
    messageInputTextView.rightAnchor.constraint(equalTo: sendButton.leftAnchor).isActive = true
    messageInputTextView.contentInset = UIEdgeInsets(prime: 12, left: 4, backside: 4, proper: 8)
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been applied")
}

override var intrinsicContentSize: CGSize {
    return .zero
}

@objc func handleSendMessage() {
    print("Button tapped.")
}

}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments