I am trying to align the float of a UIButton to the right in the header of a TableView section universally. So far I have managed to add restrictions for one screen size ...
Here is my code:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { var headerFrame:CGRect = tableView.frame let titelArr: NSArray = ["1", "2", "3", "4", "5", "6"] var title = UILabel(frame: CGRectMake(10, 10, 100, 30)) title.font = UIFont.boldSystemFontOfSize(20.0) title.text = titelArr.objectAtIndex(section) as? String title.textColor = UIColor.whiteColor() var headBttn:UIButton = UIButton.buttonWithType(UIButtonType.ContactAdd) as UIButton headBttn.frame = CGRectMake(320, 10, 30, 30) headBttn.enabled = true headBttn.titleLabel?.text = title.text headBttn.tag = titelArr.indexOfObject(titelArr.objectAtIndex(section)) headBttn.addTarget(self, action: "addItem:", forControlEvents: UIControlEvents.TouchUpInside) var headerView:UIView = UIView(frame: CGRectMake(0, 0, headerFrame.size.width, headerFrame.size.height)) headerView.backgroundColor = UIColor(red: 108/255, green: 185/255, blue: 0/255, alpha: 0.9) headerView.addSubview(title) headerView.addSubview(headBttn) return headerView }
How can I make the button float to the right? Other restrictions may remain as they are ...
thanks for your help!
// seb
source share