//导航栏左上角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
网友评论