テキスト文字列の物理的なピクセル サイズを見つけようとしています。次に、このサイズを使用して roundRectButton の長さを設定します。長さを取得するために使用しているメソッドは、CGSize を返します。それを CGFloat に変換するにはどうすればよいですか? あるいは、誰かがこれを達成するためのまったく別の方法を提案できるかもしれません。
これは私が現在持っているコードです:
// Note: tagAsString is a string of Tag names (Example "tag1, tag2, tag3")
// Note: Code to set this is not relevant to the question.
// get length of tagsAsString.
CGSize tagStringLength = [tagsAsString sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0] forWidth:100.0 lineBreakMode:UILineBreakModeTailTruncation];
// size button to fit length of string
// Note: spotTags is a roundRectButton
cell.spotTags.frame = CGRectMake(96, 33, tagStringLength, 25);
// set the title of the roundRectButton to the tag string
[cell.spotTags setTitle:tagsAsString forState:UIControlStateNormal];
上記のように、CGFloat として 4 つの引数を取る CGRectMake メソッドを使用しています。ただし、実行時エラーの原因となっている CGSize を渡しています。