gpt4 book ai didi

ios - 如何以编程方式使 UITableView 的第一部分出现在距顶部边框一定距离处?

转载 作者:行者123 更新时间:2023-11-28 08:46:33 34 4
gpt4 key购买 nike

    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
print("Inside viewForHeader")
if(section > 0){

let headerView = UIButton(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
headerView.titleLabel?.text = myOrders.allmyorders[section].customerOrder.number
let dunamicButton = UIButton(type : UIButtonType.System)
dunamicButton.backgroundColor = UIColor.clearColor()
dunamicButton.setTitle("Order number: \(myOrders.allmyorders[section].customerOrder.number)", forState: UIControlState.Normal)
dunamicButton.tag = section
dunamicButton.frame = headerView.frame
dunamicButton.enabled = true
dunamicButton.addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside)
headerView.addSubview(dunamicButton)
return headerView
}


else {
let headerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
let dunamicButton = UIButton(type : UIButtonType.System)
dunamicButton.backgroundColor = UIColor.clearColor()
dunamicButton.setTitle("Order number: \(myOrders.allmyorders[section].customerOrder.number)", forState: UIControlState.Normal)
dunamicButton.tag = section
dunamicButton.frame = CGRectMake(0, 0, 377, 30)
dunamicButton.enabled = true
dunamicButton.addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside)
headerView.addSubview(dunamicButton)

headerView.backgroundColor = UIColor.blackColor()
let buttonActive = UIButton(type : UIButtonType.System) as! UIButton
buttonActive.backgroundColor = UIColor.blueColor()
buttonActive.layer.cornerRadius = 5
buttonActive.layer.borderWidth = 1
buttonActive.alpha = 0.3
buttonActive.layer.borderColor = UIColor.whiteColor().CGColor
buttonActive.setTitle("Active Orders", forState: UIControlState.Normal)
buttonActive.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
buttonActive.frame = CGRectMake(0,0,self.view.frame.size.width/2,40)
buttonActive.addTarget(self, action: "ActiveOrdersPressed", forControlEvents: .TouchUpInside)
let buttonAllMyOrders = UIButton(type : UIButtonType.System) as! UIButton
buttonAllMyOrders.backgroundColor = UIColor.blueColor()
buttonAllMyOrders.setTitle("All My Orders", forState: UIControlState.Normal)
buttonAllMyOrders.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
buttonAllMyOrders.layer.cornerRadius = 5
buttonAllMyOrders.layer.borderWidth = 1
buttonAllMyOrders.alpha = 0.3
buttonAllMyOrders.layer.borderColor = UIColor.whiteColor().CGColor
buttonAllMyOrders.frame = CGRectMake(self.view.frame.size.width/2,0,self.view.frame.size.width/2,40)
buttonAllMyOrders.addTarget(self, action: "AllMyOrdersOrdersPressed", forControlEvents: .TouchUpInside)
headerView.backgroundColor = UIColor.clearColor()
headerView.addSubview(buttonActive)
headerView.addSubview(buttonAllMyOrders)

return headerView

}

`

我是 swift 的新手,我希望让我的 UITableView 的第一部分出现在距顶部边框一定距离处。我需要这样做来容纳两个按钮。我现在面临的问题是我的按钮与我的第一部分重叠。

Image

最佳答案

实现 tableView:heightForHeaderInSection 并返回第 0 节标题 View 的高度,根据您的代码为 40。

关于ios - 如何以编程方式使 UITableView 的第一部分出现在距顶部边框一定距离处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35146655/

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