Customizable Navigationitem, when we use the system to set Navigationitem's Leftitem or Rightitem, we will find that the item position will be biased (left side to right, left to right). When you set Navigationitem Titleview, you will see that the picture is stretched. So I made a simple package of the system Setup method, which can conveniently set the Navigationitem Leftitem,titleview,rightitem and can control the offset of item independently.
:
How to use:
First, the Custombaritem folder in the demo will be added to the project.
Second, in the file to be set to add the header file #import "Uinavigationitem+customitem.h"
Third, set
1. Set item by text
[Self.navigationitem setitemwithtitle:@ "Custom Item" Textcolor:[uicolor Redcolor] fontsize:16 Itemtype:center];
Parameter description: ①, text content ②, text color ③, font size
④, item format left corresponds to Leftitem center Titleview right corresponds to Rightitem
2. Set item by picture
[Self.navigationitem setitemwithimage:@ "Test1.png" Size:cgsizemake (48/2, 26/2) itemtype:left];
Parameter description: ①, picture name ②, picture size ③, ibid.
3. Add a click event for item
1, 22 sets of methods will return a Custombaritem instance, get this instance to add the event:
Custombaritem *rightitem = [Self.navigationitem setitemwithimage:@ "Test.png" Size:cgsizemake (39/2, 40/2) ItemType: Right];
[Rightitem addtarget:self selector: @selector (search) Event: (UIControlEventTouchUpInside)];
4. Set the item offset
The same 3 get the Custombaritem instance and set it up.
[Rightitem setoffset:10];//the larger the value, the Leftitem the more left Rightitem the right default value is 10
5. Set item size when item is set with text
[Rightitem settitleviewsize:cgsizemake (width, height)];
Detailed Description: http://ios.662p.com/thread-2294-1-1.html
Customizable navigation bar feature case iOS project source code