[英]How to set UILable/UIButton(custom) Size after adding string?
我必須在帶有標題的滾動視圖中添加許多標簽/自定義按鈕。
所以為此我得到每個字符串的長度並乘以它的字體大小並得到整個字符串的寬度,但我沒有得到每個 label 的確切值。
如果有朋友有想法告訴我。
謝謝
Ankit
有一個非常好的方法sizeWithFont:
。 你可以在這里查一下。
做一些類似的事情......!!!
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.