0

ラベルの高さを変更する次のコードがありますが、機能しません。テキストが表示されています.....何が間違っていましたか?

float storeAddress1YOffset=10;
float storeAddress1XWidth=scrollView.frame.size.width;
float storeAddressLabel1YHeight=15;
UILabel *storeAddressLabel=[[UILabel alloc]initWithFrame:CGRectMake(Xoffset,storeSectionHeight+ storeAddress1YOffset,storeAddress1XWidth, storeAddressLabel1YHeight) ];
storeAddressLabel.font=[UIFont fontWithName:@"GillSans" size:15.0f];
currentHeight=currentHeight + storeAddress1YOffset + storeAddressLabel1YHeight;
[storeAddressLabel setText:fullAddress];

CGRect labelFrame = storeAddressLabel.frame;
labelFrame.size = [fullAddress sizeWithFont:storeAddressLabel.font
                            constrainedToSize:CGSizeMake(storeAddressLabel.frame.size.width, CGFLOAT_MAX)
                                lineBreakMode:storeAddressLabel.lineBreakMode];
storeAddressLabel.frame = labelFrame;
4

1 に答える 1

1

あなたのコードは私のために働くようです。インスタンス化していない変数がいくつかあります。

float Xoffset = ?;
float storeSectionHeight = ?;
float currentHeight = ?;
NSString *fullAddress = @"?";

また、サブビューとして(私が想定している)詳細を表示しscrollViewたり、追加したりすることもありません。storeAddressLabelscrollView

プレーンを使用してこれらの欠落部分を埋めるとUIView、ラベルはテスト文字列に正しくサイズ変更されたように見えましたfullAddress。これらの欠落している部分を含め、コードをさらにいくつか含めてください。

于 2012-10-02T00:05:22.950 に答える