UISegmentedControl avec l'Image et le Titre

Je suis à l'aide d'un UISegmentedControl à l'intérieur d'un UIToolBar en tant que bouton. Je ne peux pas utiliser une normale UIButtonBarItem, parce que j'ai besoin de régler le tintColor et de support de l'iOS 4.3.
Donc je suis en utilisant le code suivant:

UISegmentedControl* searchButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"", nil]];
[searchButton setImage:[UIImage imageNamed:@"search_picto"] forSegmentAtIndex:0];
searchButton.momentary = YES;
searchButton.segmentedControlStyle = UISegmentedControlStyleBar;
searchButton.tintColor = [UIColor colorWithRed:0.27 green:0.60 blue:0.20 alpha:1.00];
[searchButton addTarget:self action:@selector(actionSearch:) forControlEvents:UIControlEventValueChanged];

Cela fonctionne très bien, mais est-il une manière que je peux avoir un Texte /Titre à côté de mon image?
La méthode setTitle: supprime l'image. Il doit y avoir un autre moyen...

Merci pour votre aide.

--

Edit:
J'ai décidé d'ajouter du texte directement sur la UIImageView comme ceci:

NSString* label = @"My Label";
UIImage* image = [self addText:label toImage:[UIImage imageNamed:@"icon"]];
[_segmentedControl insertSegmentWithImage:image atIndex:0 animated:NO];
[_segmentedControl setWidth:image.size.width + 10]; //add some margin on the right
- (UIImage *)addText:(NSString *)text toImage:(UIImage *)image {
UIFont* font = [UIFont boldSystemFontOfSize: 12];
CGSize expectedSize = [text sizeWithFont:font];
[self retinaAwareUIGraphicsBeginImageContext:CGSizeMake(image.size.width + expectedSize.width + 10, image.size.height)];
[image drawAtPoint: CGPointZero];
[[UIColor whiteColor] set];
[text drawAtPoint: CGPointMake(30, 2) withFont:font];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)retinaAwareUIGraphicsBeginImageContext:(CGSize) size {
CGFloat scale = -1.0;
if (scale<0.0) {
UIScreen *screen = [UIScreen mainScreen];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {
scale = [screen scale];
}
else {
scale = 0.0;
}
}
if (scale>0.0) {
UIGraphicsBeginImageContextWithOptions(size, NO, scale);
}
else {
UIGraphicsBeginImageContext(size);
}
}

OriginalL'auteur D-32 | 2012-11-19