Custom image or text for a UIBarButtonItem without the default bordered style.
Used instead of UIBarButtonItem
when you don't want the default bordered style that Apple applies to it. Creates a cleaner bar button item, or simply leaves more room for creative freedom!
A demo project ILBarButtonItemDemo
is included to show how ILBarButtonItem
can be integrated into a project.
-
Copy the following 3 files into your Xcode project. Be sure to check "Copy items into destination's group folder".
ILBarButtonItem.h
ILBarButtonItem.m
-
Add the line
#include "ILBarButtonItem.h"
to theYourAppName-Prefix.pch
file in the "Supporting Files" group. This way,ILBarButtonItem
will be available to every file in your project without needing to keep adding a#include
. -
In the
-viewDidLoad
method of the view controller you want the bar button item to show in, put in the following code. Note: your images should have dimensions below 44x44px for the best results.self.navigationItem.leftBarButtonItem = [ILBarButtonItem barItemWithImage:[UIImage imageNamed:@"gear.png"] selectedImage:[UIImage imageNamed:@"gearSelected.png"] target:self action:@selector(leftTapped:)]; self.navigationItem.rightBarButtonItem = [ILBarButtonItem barItemWithTitle:@"Start" themeColor:[UIColor whiteColor] target:self action:@selector(rightTapped:)];
-
At runtime, you can change the images on the button by directly editing the
customImage
andcustomSelectedImage
properties of an instance of anILBarButtonItem
.ILBarButtonItem *rightBtn = (ILBarButtonItem *)self.navigationItem.rightBarButtonItem; rightBtn.customImage = [UIImage imageNamed:@"<default image to change to>.png"]; rightBtn.customSelectedImage = [UIImage imageNamed:@"<selected image to change to>.png"];
-
The tapped action can also be changed in a similar fashion by editing the
customAction
property.
- ARC
- iOS 5.0 or later
Isaac Lim
isaacl.net
- Glyphish Pro icons
1.0
- First publish to Github
1.1 - Added iOS 7 style text buttons
ILBarButtonItem is distributed under the terms and conditions of the MIT license.
Copyright (c) 2013 isaacl.net. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.