添加字符串后如何设置UILable / UIButtoncustom大小?

问题描述

| 我必须在带有标题的滚动视图中添加标签/自定义按钮的数量。 因此,我得到每个字符串的长度,并乘以它的字体大小,并获得整个字符串的宽度,但我没有得到每个标签的确切值。  如果有任何哥们告诉我的话。谢谢Ankit     

解决方法

        做某事像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];
    ,        有一个非常好的方法
sizeWithFont:
。您可以在这里查找。     ,        使用NSString的sizeWithFont方法, iPhone UILabel sizeWithFont: 如何使-[NSString sizeWithFont:forWidth:lineBreakMode:]工作?     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...