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]

你可能感兴趣的:(Swift_常用)