而不是創建一個Xib文件並將其加載到tableview中。我在標題視圖中創建一個標籤和按鈕。如何添加按鈕和標籤之間的垂直對齊
var btnTimeZone = UIButton(type: .Custom)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.btnTimeZone.titleLabel?.font = UIFont.boldSystemFontOfSize(14.0)
self.btnTimeZone.backgroundColor = UIColor.clearColor()
self.btnTimeZone.setTitleColor(UIColor.blackColor(), forState: .Normal)
self.btnTimeZone.addTarget(self, action: #selector(self.selectClicked), forControlEvents: UIControlEvents.TouchUpInside)
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 150))
headerView.layer.borderWidth = 2
headerView.layer.borderColor = UIColor.whiteColor().CGColor
headerView.backgroundColor = ClientConfiguration.primaryUIColor()
let myLabel = UILabel()
myLabel.frame = CGRectMake(0, 0, tableView.frame.width - 70, 30)
myLabel.font = UIFont.boldSystemFontOfSize(10)
myLabel.backgroundColor = ClientConfiguration.primaryUIColor()
myLabel.textColor = UIColor.whiteColor()
myLabel.textAlignment = .Left
myLabel.text = "please Select your Time Zone"
let frame = CGRectMake(0, 0,headerView.frame.width , 50)
self.btnTimeZone.frame = frame
headerView.addSubview(myLabel)
headerView.addSubview(self.btnTimeZone)
return headerView
}
我想在標題視圖中按鈕上方的標籤,但我不能這個..? 我該怎麼做這個.. ??
如果你支持iOS 9+只有你可以使用錨點 –
你能指導它嗎 – iron