Reputation: 1411
I always have problem say: cannot convert value of type of UIImage?.Type' to expected argument type 'UIImage?'
I used this code below:
btn.setBackgroundImage(UIImage?: welcome.png ,for : UIControlState.normal, barMetrics: UIBarMetrics.default)
Upvotes: 3
Views: 2406
Reputation: 73
Swift 5.0
btn.setBackgroundImage(UIImage(named: "welcome"), for: .normal, barMetrics: .default)
Upvotes: 0
Reputation: 361
Obj-C:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 40.0f)];
[btn addTarget:self action:@selector(buttonEN:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage imageNamed:@"cys_lang_en.png"] forState:UIControlStateNormal];
UIBarButtonItem *eng_btn = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = eng_btn;
Swift 4.0:
var btn = UIButton(type: .custom)
btn.frame = CGRect(x: 0.0, y: 0.0, width: 25.0, height: 40.0)
btn.addTarget(self, action: Selector("buttonEN:"), for: .touchUpInside)
btn.setImage(UIImage(named: "cys_lang_en.png"), for: .normal)
var eng_btn = UIBarButtonItem(customView: btn)
navigationItem?.rightBarButtonItem = eng_btn
Upvotes: 0
Reputation:
Try this:
btn.setBackgroundImage(UIImage(named: "welcome") ,for : UIControlState.normal)
Upvotes: 3
Reputation: 3937
btn.setBackgroundImage(UIImage(named: "welcome.png"), for: .normal, barMetrics: .default)
Upvotes: 0