给导航栏上的button设置背景按钮,参考代码:

//导航栏左上角icon

//create a new button

let button: UIButton = UIButton(type: UIButtonType.System)

//set background image for button

button.setBackgroundImage(image, forState: UIControlState.Normal)

//add function for button

button.addTarget(self, action: "fbButtonPressed", forControlEvents: UIControlEvents.TouchUpInside)

//set frame

button.frame = CGRectMake(0, 0, 30, 30 )

let barButton = UIBarButtonItem(customView: button)

//assign button to navigationbar

self.navigationItem.leftBarButtonItem = barButton

你可能感兴趣的:(给导航栏上的button设置背景按钮,参考代码:)