TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Sep 2016 |
Maintained by [Jakub].
With the regular UIButton
you are able to set title and also image for that button but that content WILL NOT be centered horizontally (only title will).
JTImageButton is a UIButton
subclass that makes TITLE+IMAGE work easier. Your image and title together WILL BE centered horizontally. You will be also able to resize provided image and change it’s color easier, so basically all you have to provide is a text as a title and image (NO MORE image asset editing to get an image that you want in a button).
There are two ways to add the JTImageButton library to your project. Add it as a regular library or install it through CocoaPods.
pod 'JTImageButton'
You may also quick try the example project with
pod try JTImageButton
Library requires target iOS 7.0 and above
Create UIButton in your .xib/storyboard
with IBOutlet
and set class to JTImageButton
(Also button type should be Custom
) OR initWithFrame
if you need it programatically.
Use - (void)createTitle:withIcon:font:iconHeight:iconOffsetY:
Or to keep original image size use - (void)createTitle:withIcon:font:iconOffsetY:
[self.btn createTitle:@"DONE"
withIcon:[UIImage imageNamed:@"icon_tick"]
font:nil
iconHeight:JTImageButtonIconHeightDefault
iconOffsetY:JTImageButtonIconOffsetYNone];
iconHeight
< original image
-> scaled
iconHeight
>= original image
-> original image
iconHeight
== 0
OR JTImageButtonIconHeightDefault
-> scaled by title
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, assign) UIColor *iconColor;
@property (nonatomic, strong) UIColor *bgColor;
@property (nonatomic, strong) UIColor *borderColor;
@property (nonatomic, assign) JTImageButtonPadding padding; // Small/Medium/Big/None
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) JTImageButtonIconSide iconSide; // Left/Right
@property (nonatomic, assign) CGFloat highlightAlpha;
@property (nonatomic, assign) CGFloat disableAlpha;
@property (nonatomic, assign) BOOL touchEffectEnabled;
This library is open-sourced by Jakub Truhlar.
The MIT License (MIT) Copyright © 2015 Jakub Truhlar