inputView
The custom input view to display when the responder becomes the first responder.
This property is typically used to provide a view to replace the system-supplied keyboard that’s presented for UITextField
and UITextView
objects.
The value of this read-only property is nil
. A responder object that requires a custom view to gather input from the user should redeclare this property as read-write and use it to manage its custom input view. When the responder becomes the first responder, the responder infrastructure presents the specified input view automatically. Similarly, when the responder resigns its first responder status, the responder infrastructure automatically dismisses the specified input view.
inputAccessoryView
The custom input accessory view to display when the responder becomes the first responder.
This property is typically used to attach an accessory view to the system-supplied keyboard that’s presented for UITextField
and UITextView
objects.
The value of this read-only property is nil
. If you want to attach custom controls to a system-supplied input view (such as the system keyboard) or to a custom input view (one you provide in the inputView
property), redeclare this property as read-write in a UIResponder
subclass. You can then use this property to manage a custom accessory view. When the responder becomes the first responder, the responder infrastructure attaches the accessory view to the appropriate input view before displaying it.
Repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
addSubview(backgroundView)
addSubview(topStackView)
addSubview(contentView)
addSubview(separatorLine)
contentView.addSubview(middleContentViewWrapper)
contentView.addSubview(leftStackView)
contentView.addSubview(rightStackView)
contentView.addSubview(bottomStackView)
middleContentViewWrapper.addSubview(inputTextView)
middleContentView = inputTextView
// The constraints within the InputBarAccessoryView
separatorLine.addConstraints(topAnchor, left: backgroundView.leftAnchor, right: backgroundView.rightAnchor, heightConstant: separatorLine.height)
backgroundViewLayoutSet = NSLayoutConstraintSet(
top: backgroundView.topAnchor.constraint(equalTo: topStackView.bottomAnchor),
bottom: backgroundView.bottomAnchor.constraint(equalTo: bottomAnchor),
left: backgroundView.leftAnchor.constraint(equalTo: leftAnchor, constant: frameInsets.left),
right: backgroundView.rightAnchor.constraint(equalTo: rightAnchor, constant: -frameInsets.right)
)
topStackViewLayoutSet = NSLayoutConstraintSet(
top: topStackView.topAnchor.constraint(equalTo: topAnchor, constant: topStackViewPadding.top),
bottom: topStackView.bottomAnchor.constraint(equalTo: contentView.topAnchor, constant: -padding.top),
left: topStackView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor, constant: topStackViewPadding.left + frameInsets.left),
right: topStackView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor, constant: -(topStackViewPadding.right + frameInsets.right))
)
contentViewLayoutSet = NSLayoutConstraintSet(
top: contentView.topAnchor.constraint(equalTo: topStackView.bottomAnchor, constant: padding.top),
bottom: contentView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -padding.bottom),
left: contentView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor, constant: padding.left + frameInsets.left),
right: contentView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor, constant: -(padding.right + frameInsets.right))
)
// Constraints Within the contentView
middleContentViewLayoutSet = NSLayoutConstraintSet(
top: middleContentViewWrapper.topAnchor.constraint(equalTo: contentView.topAnchor, constant: middleContentViewPadding.top),
bottom: middleContentViewWrapper.bottomAnchor.constraint(equalTo: bottomStackView.topAnchor, constant: -middleContentViewPadding.bottom),
left: middleContentViewWrapper.leftAnchor.constraint(equalTo: leftStackView.rightAnchor, constant: middleContentViewPadding.left),
right: middleContentViewWrapper.rightAnchor.constraint(equalTo: rightStackView.leftAnchor, constant: -middleContentViewPadding.right)
)
inputTextView.fillSuperview()
maxTextViewHeight = calculateMaxTextViewHeight()
textViewHeightAnchor = inputTextView.heightAnchor.constraint(equalToConstant: maxTextViewHeight)
leftStackViewLayoutSet = NSLayoutConstraintSet(
top: leftStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
bottom: leftStackView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
left: leftStackView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0),
width: leftStackView.widthAnchor.constraint(equalToConstant: leftStackViewWidthConstant)
)
rightStackViewLayoutSet = NSLayoutConstraintSet(
top: rightStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
bottom: rightStackView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
right: rightStackView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0),
width: rightStackView.widthAnchor.constraint(equalToConstant: rightStackViewWidthConstant)
)
bottomStackViewLayoutSet = NSLayoutConstraintSet(
top: bottomStackView.topAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: middleContentViewPadding.bottom),
bottom: bottomStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0),
left: bottomStackView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0),
right: bottomStackView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0)
)