func createFakeAndSearchCurrentLocationBarButton (vw: UIViewController) {
let fakeCurrentLocationGo = UIButton(type: .custom)
fakeCurrentLocationGo.setImage(UIImage(named: "reallocationgo50"), for: .normal)
fakeCurrentLocationGo.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
fakeCurrentLocationGo.addTarget(vw, action: #selector(goToMyCurrentLocationPin), for: .touchUpInside)
let leftItem = UIBarButtonItem(customView: fakeCurrentLocationGo)
let searchLocationBtn = UIButton(type: .custom)
searchLocationBtn.setImage(UIImage(named: "search"), for: .normal)
searchLocationBtn.frame = CGRect(x: 0, y: 0, width: 15, height: 15)
fakeCurrentLocationGo.addTarget(vw, action: #selector(searchLocationHandle), for: .touchUpInside)
let rightItem = UIBarButtonItem(customView: searchLocationBtn)
vw.navigationItem.setRightBarButtonItems([leftItem,rightItem], animated: true)
}
Nguồn
2017-12-16 23:24:47
làm thế nào bạn thêm nút? – Johnykutty
tôi chỉ muốn đặt nút bấm bằng khung hình, nhưng nó gọi phương thức khi tôi nhấp vào bên ngoài nút –