gpt4 book ai didi

iphone - 如何为 UIToolbar 上的按钮添加滚动?

转载 作者:行者123 更新时间:2023-11-29 04:19:27 25 4
gpt4 key购买 nike

如何为 UIToolbar 上的 UIBarButtonItem 按钮添加滚动(在工具栏上放置许多按钮)?

buttonDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonDoneDown)];
NSArray *itemsArray = [NSArray arrayWithObjects:buttonDone, nil];
[toolbar setItems:itemsArray];

非常感谢您的帮助!

最佳答案

对于 swift

假设我想向我的 UIToolBar 添加 7 个 UIBarButtonItem

首先创建一个scrollView,然后添加toolBar作为 subview

// In viewDidLoad

let scrollView = UIScrollView(frame: CGRect(x: 0, y: view.frame.height-44, width: view.frame.width, height: 50))

let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 1000, height: scrollView.frame.height))

let btn1 = UIBarButtonItem()
let btn2 = UIBarButtonItem()
let btn3 = UIBarButtonItem()
let btn4 = UIBarButtonItem()
let btn5 = UIBarButtonItem()
let btn6 = UIBarButtonItem()
let btn7 = UIBarButtonItem()
toolBar.items = [btn1, btn2, btn3, btn4, btn5, btn6, btn7]

scrollView.addSubview(toolBar)

// The below line is important for scrollView to work
scrollView.contentSize = CGSize(width: 1000, height: 50)

最后添加scrollView作为你的textField inputAccessoryView

textField.inputAccessoryView = scrollView

希望对你有帮助:]

关于iphone - 如何为 UIToolbar 上的按钮添加滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13155244/

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