iOS笔记
记录一些iOS开发路上碰到的大坑小坑。
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&&设置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