Swift_常用

let WIDTH = UIScreen.mainScreen().bounds.size.width
let HETGHT = UIScreen.mainScreen().bounds.size.height

2.隨機色

let COLORAUTO = UIColor(red:CGFloat(arc4random_uniform(255))/CGFloat(255.0), green:CGFloat(arc4random_uniform(255))/CGFloat(255.0), blue:CGFloat(arc4random_uniform(255))/CGFloat(255.0), alpha:1.00)

3.導航單個按鈕

 let buttonRight = UIButton(frame:CGRectMake(0,0,50,30))
 buttonRight.setTitle("確定", forState: UIControlState.Normal)
 buttonRight.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
 let barButton = UIBarButtonItem(customView: buttonRight)
 self.navigationItem.rightBarButtonItem = barButton

4.自定義導航多個按鈕

let gap = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil,action: nil)
gap.width = 15
let spacer = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil,action: nil)
spacer.width = -10;
let barButton2 = UIButton.init(frame: CGRectMake(0, 0, 80, 30))
barButton2.setTitle("按鈕1", forState: UIControlState.Normal)
barButton2.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
let barButton22 = UIBarButtonItem(customView: barButton2)
let barButton1 = UIButton.init(frame: CGRectMake(0, 0, 80, 30))
barButton1.setTitle("按鈕2", forState: UIControlState.Normal)
barButton1.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
let barButton11 = UIBarButtonItem(customView: barButton1)
 self.navigationItem.rightBarButtonItems = [spacer,barButton11,gap,barButton22]
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容