The content is actually very simple, but sometimes we forget it. When we set rightBarButton/leftBarbutton, sometimes we find that the system is not very nice and we want to customize it. So we have this idea:
Directly add the Code as follows:
NSInteger width = [[UIScreen mainScreen] bounds]. size. width-20; // obtain the system width
UIView * view_title = [[UIView alloc] initWithFrame: CGRectMake (width, 10, 20, 20)]; // generate custom UIViewUIButton * btnItem = [UIButton alloc] initWithFrame: CGRectMake (0, 0, 20, 20)]; UIImage * image = [UIImage imageNamed: @ "down.png"]; [btnItem setImage: image forState: UIControlStateNormal]; [btnItem addTarget: self action: @ selector (favoriteBtnItem) forControlEvents: UIControlEventTouchUpInside];
[View_title addSubview: btnItem];
// Add the UIView to UIBarBtn
UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithCustomView: view_title];
// Set the button position on the right to self. navigationItem. rightBarButtonItem = btn;