开发者

How to set UILable/UIButton(custom) Size after adding string?

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


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];


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


Use the sizeWithFont method of NSString,

iPhone UILabel sizeWithFont:

How do I get -[NSString sizeWithFont:forWidth:lineBreakMode:] to work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜