0

I have to add number of labels/custom buttons in scroll view with there title.

so for that i get length of each string and multiply with it`s font size and get width of whole string but i am not get exact value for each label.

if any buddy have idea that tell me.

Thanks

Ankit

AJPatel
  • 2,291
  • 23
  • 42

3 Answers3

2

There is a very nice method sizeWithFont:. You can look it up here.

Anton
  • 2,342
  • 15
  • 17
2

Do Something like dis...!!!

NSString * titleString=pod.title;
    CGSize constraint = CGSizeMake(200,999);
    CGSize size = [titleString sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    titleLabel=[[[UILabel alloc] initWithFrame:CGRectMake(120, 24, 200, size.height)] autorelease];
    [titleLabel setText:titleString];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setNumberOfLines:0];
    titleLabel.lineBreakMode=UILineBreakModeWordWrap;
    [titleLabel setFont:[UIFont systemFontOfSize:14]];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextAlignment:UITextAlignmentCenter];
    [scrollView addSubview:titleLabel];
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
Suny
  • 1,175
  • 1
  • 10
  • 27
  • thanks for give ur time my friends... Hey suny i think this one also compatible for UIButton(cus.). – AJPatel May 30 '11 at 11:11