Reputation: 171
Is there any way to display UILabel
like this
or
where I will get the data in UILabel
and the numbers of labels to display dynamically.
Upvotes: 0
Views: 134
Reputation: 3399
Building from comment by iAmbitious:
First case:
NSArray *array = [NSArray arrayWithObjects:@"One",@"Two",@"Three", nil];
NSMutableString *compoundString = [NSMutableString string];
NSString *bulletString = [NSString stringWithFormat:@"%C",0x2022];
for (NSString *str in array) {
NSString *tempString = [NSString stringWithFormat:@"%@ %@\n",bulletString,str];
[compoundString appendString:tempString];
}
self.textView.text=compoundString;
Second case: Replace the for loop with the following for loop-
for (NSString *str in array) {
NSString *tempString = [NSString stringWithFormat:@"%d. %@\n",[array indexOfObject:str]+1,str];
[compoundString appendString:tempString];
}
The above used a text view. If you want to use a label set the number of lines property to zero and set the height of label dynamically like below. You can achieve the same:
CGSize lineSize = [@"DummyString" sizeWithFont:self.label.font] ;
CGFloat labelHeight = lineSize.height*array.count;
CGRect tempFrame = self.label.frame;
tempFrame.size.height=labelHeight;
self.label.frame=tempFrame;
Upvotes: 1