try this...
create a Category for UISegmentedControl
,suppose UISegmentedControl+Multiline
in UISegmentedControl+Multiline.h
#import <UIKit/UIKit.h>
@interface UISegmentedControl (Multiline)
- (void)insertSegmentWithMultilineTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated;
@end
and in UISegmentedControl+Multiline.m
#import "UISegmentedControl+Multiline.h"
@interface UIView (LayerShot)
- (UIImage *)imageFromLayer;
@end
@implementation UIView (LayerShot)
- (UIImage *)imageFromLayer {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
@implementation UISegmentedControl (Multiline)
- (void)insertSegmentWithMultilineTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTextColor:[self tintColor]];
[label setBackgroundColor:[UIColor clearColor]];
[label setFont:[UIFont systemFontOfSize:13]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setLineBreakMode:NSLineBreakByWordWrapping];
[label setNumberOfLines:0];
[label setText:title];
[label sizeToFit];
[self insertSegmentWithImage:[label imageFromLayer] atIndex:segment animated:animated];
}
@end
finally import UISegmentedControl+Multiline.h
in your class and use as follows
UISegmentedControl * segmentControl = [[UISegmentedControl alloc]initWithFrame:CGRectMake(3, 66, 314, 30)];
[segmentControl insertSegmentWithMultilineTitle:@"First\nLine" atIndex:0 animated:YES];
[segmentControl insertSegmentWithMultilineTitle:@"Second\nLine" atIndex:1 animated:YES];
[segmentControl insertSegmentWithMultilineTitle:@"Third\nLine" atIndex:2 animated:YES];
[segmentControl setSelectedSegmentIndex:0];
[segmentControl addTarget:self action:@selector(segmentControlClicked:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentControl];