Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can add a category to the class and try overriding <code>layoutSubviews:</code> from within the category. (This technique <a href="https://stackoverflow.com/questions/4319112/how-do-i-change-the-background-of-a-uinavigationbar/4319201#4319201">has been suggested for customizing navigation bars</a>, and it may well work here too.)</p> <p>Here's how you'd make a category, <a href="https://stackoverflow.com/questions/6934637/overwriting-uinavigationbar-to-set-a-default-titleview/6934790#6934790">taken from my answer here</a>. In your case, remember to substitute <code>UIView</code> for <code>UINavigationController</code>.</p> <p>Hit Command+N or open the "New File" dialog. Next, choose "Objective-C category" from the Cocoa Touch menu:</p> <p><img src="https://i.stack.imgur.com/ZGYEw.png" alt="Creating a category"></p> <p>Click Next and you will be prompted to enter the name of the class that you would like to add methods to as a category. It should look something like this:</p> <p><img src="https://i.stack.imgur.com/NZ1II.png" alt="Making a Category on the NavBar"></p> <p>Then, you should end up with a save file dialog. A quick note about convention here. Convention is to name a category after the original class, the plus sign, and then a description of what you're adding. Here's what yours might look like:</p> <p><img src="https://i.stack.imgur.com/y7jqx.png" alt="Category Naming Convention"></p> <p>Once you save your file, you will need get something like this: </p> <p><img src="https://i.stack.imgur.com/u6xqb.png" alt="Empty Category"></p> <p><strong>Edit:</strong></p> <p>If you want to go ahead and do this without a category, then your best bet is to make a subclass of UIView and then subclass <em>that</em> class wherever you want your custom behavior. Another advantage over a category is that your method will only work where you explicitly use the custom class. In categories, the method gets added everywhere.</p> <p>Good luck! </p>
 

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