Note that there are some explanatory texts on larger screens.

plurals
  1. POAlter a UIBarButtonItem view to be transparent programmatically
    primarykey
    data
    text
    <p>I've had trouble getting this to work, nowhere have I seen a working example on the web. Now offering bounty on this as its making me crazy. It should be easy, but that doesn't seem to be the case.</p> <p>I'd like my buttons on my UINavigationBar to be semi-transparent such that they allow the background of whatever is on the UINavigationBar to show through. This effect is seen in many applications, image examples below. You can do this by setting a custom background on the item, which i think is an unacceptable solution because it requires that you prepare images beforehand, and they won't be adaptable for variable buttons etc. They will not look like Apple UI and I don't believe there is a reason to do this either, UIKit is already drawing the background for these buttons, we just need to change it. The correct solution uses the bar items and views generated by Apple's apis.</p> <p>UIBarButtonItem is not a UIView subclass. When you create one and add it to a UINavigationBar, some code somewhere in the framework draws a view for it. The framework methods seem to resist anything related to allowing transparency of the bar items, such as the tintColor property.</p> <p>For example, this does NOT work:</p> <pre><code> UINavigationItem *item = [[UINavigationItem alloc] init]; UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"SUCKS" style:UIBarButtonItemStyleBordered target:self action:@selector(whatever:)]; editButton.tintColor = [UIColor colorWithWhite:0.4 alpha:0.3]; item.leftBarButtonItem = editButton; </code></pre> <p>Nothing I do will make UINavigationBar allow semi-transparency for its bar items. I believe at runtime we need to:</p> <ol> <li>Get the image for the bar item</li> <li>Mask it for transparency</li> <li>Set the new image on the bar item</li> </ol> <p>But I haven't been able to get the image at runtime or mask it properly. How do you do this?</p> <p><img src="https://farm8.staticflickr.com/7014/6701703007_5b78f9bfbb.jpg" alt="Like This"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload