I would like to wrap the text of my uiSegmentedControl to have more then one line in it. Actually it looks like this. You see the middle option reads "search in title an...", which should be wrapped :
My Code is:
var sSearchinTitle=getStringResourceByName("searchtitle_" + AppProperties.sharedInstance.sAppLanguage);
var sSearchinPreface=getStringResourceByName("searchpreface_" + AppProperties.sharedInstance.sAppLanguage);
var sSearchOverall=getStringResourceByName("searchoverall_" + AppProperties.sharedInstance.sAppLanguage);
arraySearchTypes = [sSearchinTitle, sSearchinPreface, sSearchOverall];
segmentcontrol_SearchType = UISegmentedControl(items: arraySearchTypes);
let font = UIFont.systemFontOfSize(fFontsize_SearchtypeValues)
segmentcontrol_SearchType.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
segmentcontrol_SearchType.frame.origin = CGPoint(x: spaceYElements, y: drawy);
segmentcontrol_SearchType.selectedSegmentIndex = saved_TextSizeTextViewer;
segmentcontrol_SearchType.sizeToFit();
self.view.addSubview(segmentcontrol_SearchType);
var segmentcontrolheigth=segmentcontrol_SearchType.frame.height;
var segmentcontrolwidth=segmentcontrol_SearchType.frame.width;
I found something in other forums which should be a solution for objective C, but I don't understand this :-)
[[UILabel appearanceWhenContainedIn:[UISegmentedControl class], nil] setNumberOfLines:0];
any help ? (thanks :-) )
UPDATE I tried the following, which doesn't work either. I go through all UILabels and set the numberOfLines = 0;
segmentcontrol_SearchType = UISegmentedControl(items: arraySearchTypes);
let font = UIFont.systemFontOfSize(fFontsize_SearchtypeValues)
segmentcontrol_SearchType.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
segmentcontrol_SearchType.frame.origin = CGPoint(x: spaceYElements, y: drawy);
segmentcontrol_SearchType.selectedSegmentIndex = saved_TextSizeTextViewer;
// Go through all sublabels and set wrapping
for labels in segmentcontrol_SearchType.subviews {
if labels.isKindOfClass(UILabel){
var myLabel:UILabel=labels as! UILabel;
myLabel.numberOfLines = 0;
}
}
segmentcontrol_SearchType.sizeToFit();