Not that I knew. I think you will need to create images of your text labels (either in advance in your graphic tool of choice, or you can create them programmatically at run time).
If you want to do this programmatically, a method like the following can do this. It creates a center alignment using the text you pass that performs word wrap.
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];
item.image = [self makeThumbnailFromText:@"Tab Bar One"];
item.title = nil;
item = [self.tabBar.items objectAtIndex:1];
item.image = [self makeThumbnailFromText:@"Tab Bar Two"];
item.title = nil;
, , , . , , .
- (UIImage *)makeThumbnailFromText:(NSString *)string {
CGSize imageSize = CGSizeMake(60, 80);
CGFloat fontSize = 13.0;
NSString *fontName = @"Helvetica-Bold";
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
CGFloat lineSpacing = fontSize * 1.2;
UIGraphicsBeginImageContextWithOptions(imageSize, false, 0);
NSDictionary *attributes = @{NSFontAttributeName: font};
NSArray <NSString *> *words = [string componentsSeparatedByString:@" "];
NSMutableArray <NSDictionary *> *lines = [NSMutableArray array];
NSString *lineThusFar;
CGSize sizeThusFar = CGSizeZero;
for (NSString *word in words) {
NSString *currentLine = lineThusFar ? [NSString stringWithFormat:@"%@ %@", lineThusFar, word] : word;
CGSize size = [currentLine sizeWithAttributes: attributes];
if (size.width > imageSize.width && lineThusFar) {
[lines addObject:@{@"text": lineThusFar, @"size": [NSValue valueWithCGSize: sizeThusFar]}];
lineThusFar = word;
sizeThusFar = [word sizeWithAttributes: attributes];
} else {
lineThusFar = currentLine;
sizeThusFar = size;
}
}
if (lineThusFar) {
[lines addObject:@{@"text": lineThusFar, @"size": [NSValue valueWithCGSize: sizeThusFar]}];
}
CGFloat totalSize = (lines.count - 1) * lineSpacing + fontSize;
CGFloat topMargin = (imageSize.height - totalSize) / 2.0;
for (NSInteger i = 0; i < lines.count; i++) {
CGFloat x = (imageSize.width - [lines[i][@"size"] CGSizeValue].width) / 2.0;
CGFloat y = topMargin + i * lineSpacing;
[lines[i][@"text"] drawAtPoint:CGPointMake(x, y) withAttributes: attributes];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Swift :
func makeThumbnailFromText(text: String) -> UIImage {
struct LineOfText {
var string: String
var size: CGSize
}
let imageSize = CGSize(width: 60, height: 80)
let fontSize: CGFloat = 13.0
let fontName = "Helvetica-Bold"
let font = UIFont(name: fontName, size: fontSize)!
let lineSpacing = fontSize * 1.2
UIGraphicsBeginImageContextWithOptions(imageSize, false, 0)
let attributes = [NSFontAttributeName: font]
let words = text.componentsSeparatedByString(" ")
var lines = [LineOfText]()
var lineThusFar: LineOfText?
for word in words {
let currentLine = lineThusFar?.string == nil ? word : "\(lineThusFar!.string) \(word)"
let size = currentLine.sizeWithAttributes(attributes)
if size.width > imageSize.width && lineThusFar != nil {
lines.append(lineThusFar!)
lineThusFar = LineOfText(string: word, size: word.sizeWithAttributes(attributes))
} else {
lineThusFar = LineOfText(string: currentLine, size: size)
}
}
if lineThusFar != nil { lines.append(lineThusFar!) }
let totalSize = CGFloat(lines.count - 1) * lineSpacing + fontSize
let topMargin = (imageSize.height - totalSize) / 2.0
for (index, line) in lines.enumerate() {
let x = (imageSize.width - line.size.width) / 2.0
let y = topMargin + CGFloat(index) * lineSpacing
line.string.drawAtPoint(CGPoint(x: x, y: y), withAttributes: attributes)
}
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
var item = tabBar.items![0]
item.image = makeThumbnailFromText("Tab Bar One")
item.title = nil;
item = tabBar.items![1]
item.image = makeThumbnailFromText("Tab Bar Two")
item.title = nil;