gpt4 book ai didi

ios - 将 UIButton 放置在具有约束的 UIScrollView 底部

转载 作者:行者123 更新时间:2023-11-30 11:24:33 25 4
gpt4 key购买 nike

我有一个包含三个文本字段/ TextView 字段的 View ,为了使 View 在键盘出现时可滚动,我将所有元素放入 ScrollView 中。元素之前不在框架之外,因此 contentSize 应该与全屏大小相同,然后当键盘出现时,因此当键盘出现时,我将 ScrollView 的底部约束更新为从 View 底部开始的 -keyboardHeight然后它可以在键盘上方滚动..

这一切都工作正常,问题是在 ScrollView 的底部添加一个按钮,该按钮引导/拖尾到 View 的侧面和底部。

看图片:

Current view, with button hidden behind navigation bar

Where i would like the button to be. Approx 20 margin to right.left.bottom

我正在使用 SnapKit 来设置我的约束,对于按钮我想做这样的事情:

    sharebutton.snp.makeConstraints { (make) in
make.width.left.right.equalToSuperview()
make.bottom.equalToSuperview().offset(-20)
}

( super View / ScrollView 已设置为距两侧 20 的边距)

//编辑:添加代码 ->

override func viewDidLayoutSubviews() {
scrollview.contentSize = CGSize(width: centerView.frame.width, height: view.frame.height)
}

override func viewDidLoad() {
super.viewDidLoad()

self.title = "title"
view.backgroundColor = .white

view.addSubview(scrollview)

scrollview.addSubview(sharebutton)
scrollview.addSubview(subjectField)
scrollview.addSubview(messageField)
scrollview.addSubview(datepicker)
scrollview.addSubview(addressTable)
addressTable.dataSource = self
addressTable.delegate = self
addressTable.separatorStyle = .none
addressTable.keyboardDismissMode = .onDrag
addressTable.separatorStyle = .singleLineEtched

subjectField.placeholder = "content"
datepicker.setTitle("topbutton", for: .normal)
datepicker.setTitleColor(.black, for: .normal)
datepicker.setTitleColor(UIColor.ME.border, for: .highlighted)
datepicker.titleLabel?.font = UIFont.ME.button
datepicker.layer.borderWidth = 1
datepicker.layer.cornerRadius = 3
datepicker.layer.borderColor = UIColor.ME.border.cgColor
datepicker.addTarget(self, action: #selector(showDates), for: .touchUpInside)

sharebutton.setTitle("Share", for: .normal)
sharebutton.backgroundColor = UIColor.ME.buttonMainBlue
sharebutton.addTarget(self, action: #selector(shareClicked), for: .touchUpInside)

scrollview.backgroundColor = .red
scrollview.snp.makeConstraints { (make) in
make.top.bottom.equalToSuperview()
make.left.width.right.equalTo(centerView)
}

datepicker.snp.makeConstraints { (make) in
make.top.equalToSuperview().offset(paddingGlobal)
make.left.width.right.equalToSuperview()
make.height.equalTo(50)
}

addressTable.snp.makeConstraints { (make) in
make.top.equalTo(datepicker.snp.bottom)
make.left.right.equalTo(datepicker)
make.height.equalTo(200)
}

subjectField.snp.makeConstraints { (make) in
make.top.equalTo(datepicker.snp.bottom).offset(20)
make.left.right.equalToSuperview()
}

messageField.snp.makeConstraints { (make) in
make.top.equalTo(subjectField.snp.bottom).offset(20)
make.height.equalTo(200)
make.left.right.equalToSuperview()
}

sharebutton.snp.makeConstraints { (make) in
make.width.left.right.equalToSuperview()
make.bottom.equalToSuperview().offset(-20)
}
}

有什么想法吗?

最佳答案

您需要首先在 scrollView subview 中添加一个 UIView (例如,将其命名为 containerView),然后将所有 uielement(例如,textfield/textview、UIButton)添加到该容器 View 的 subview 。

关于ios - 将 UIButton 放置在具有约束的 UIScrollView 底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50897507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com