iOS筆記

記錄一些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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容