記錄一些iOS開發(fā)路上碰到的大坑小坑。
2016.7.21
1. tabbar半透明效果
let tabBarAppearance = UITabBar.appearance()
tabBarAppearance.translucent = false
2. storyboard獲取container view的controller
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
? ? if (segue.identifier == "UserDetailSegueSB") {
? ? ? ? tableVC = segue.destinationViewController as? UserDetailTableViewController
? ? ? ? tableVC?.tableView.delegate = self
? ? ? ? tableVC?.tableView.tableHeaderView = nil
? ? }
}
3. 隱藏table view Grouped布局中頂部多出的空白部分
tableView.tableHeaderView = UIView(frame: CGRectMake(0, 0, 0, 0.01))
4. 隱藏table view Plain布局中底部多余的Separator&&設(shè)置footer view背景顏色
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
? ? let sectionFooterView: UIView = UIView()
? ? sectionFooterView.backgroundColor = GrayBackgroundClor
? ? return sectionFooterView
}
或者
func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
? ? ?view.tintColor = UIColor.clearColor()
}
5. table cell失去焦點時取消高亮
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
? ? tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
刪除高亮效果
selectionStyle = .Gray
6. 刪除table view Grouped布局中separator左邊空白
tableView.separatorInset = UIEdgeInsetsZero
tableView.layoutMargins = UIEdgeInsetsZero
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
? ? let cell = UserDetailCell.cellFor(tableView)
? ? cell.titleLabel.text = "text"
? ? //? ? ? ? cell.separatorInset = UIEdgeInsetsZero
? ? //? ? ? ? cell.layoutMargins = UIEdgeInsetsZero
? ? return cell
}
7. UISearchBar圓角
searchBar.frame = CGRectMake(0, 0, ScreenWidth * 0.7, 30)
searchBar.backgroundImage = UIImage()
let searchTextField: UITextField = searchBar.valueForKey("searchField") as! UITextField
searchTextField.backgroundColor = UIColor.whiteColor()
searchTextField.layer.masksToBounds = true
searchTextField.layer.cornerRadius = 15
searchTextField.layer.borderColor = UIColor.whiteColor().CGColor
searchTextField.layer.borderWidth = 1
searchBar.barTintColor = UIColor.whiteColor()
searchBar.placeholder = "請輸入商品名稱"
searchBar.delegate = self
navigationItem.titleView = searchBar