I want to set image from UIImageView.image to my bar button. The bar button works fine when i set the image giving it’s name (eg. @”cameraImageButton.png”), however when i do myBarButton.image = UIImageView.image (and this UIImage exists, consist same @”cameraImageButton.png”) the button doesn’t show up.
Here is the code that doesn’t work:
UIBarButtonItem *cancelBarButton = [[ UIBarButtonItem alloc ] initWithTitle: @"Cancel" style: UIBarButtonItemStyleBordered target: self action: @selector(done)];
cancelBarButton.image = cancelImageView.image;
And here is the one that works (but i want to set image from cancelImageView):
UIBarButtonItem *saveBarButton = [[ UIBarButtonItem alloc ] initWithTitle: @"Save" style: UIBarButtonItemStyleBordered target: self action: @selector(takePhoto)];
saveBarButton.image = [UIImage imageNamed:[NSString stringWithFormat:@"cameraImageButton.png"]];
//init for flexItem and cancelBarButton
NSArray *items = [NSArray arrayWithObjects: cancelBarButton, flexItem, saveBarButton, nil];
[cameraToolbar setItems:items animated:NO];
UIImageView.imageis a property not an object. It is@property(nonatomic, retain) UIImage *imagein UIImageView class and also inUIBarButtonItemClass. Only object or nil can be passed to set the property.