我有一个应用程序,其中我有一个按钮需要位于动态标签的末尾,就像附加它一样,我试过这个,但它有时显示正常(正确位置),有时不正常(不在正确的位置)方式。我正在这样做。我还需要将标签始终定位在中心`
label = [[UILabel alloc]init];
[label setFrame:CGRectMake(105,9,160, 30)];
[label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
label.textAlignment = UITextAlignmentLeft;
label.numberOfLines = 1;
label.text=myString;
[[self.view viewWithTag:300] addSubview:label];
CGSize expectedLabelSize = [label.text sizeWithFont:label.font];
CGRect newFrame = label.frame;
newFrame.size = expectedLabelSize;
if(newFrame.size.width>160.0)
newFrame.size.width=150.0;
label.frame = newFrame;
[label setCenter:CGPointMake(300/2,40/2)];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(newFrame.origin.x+newFrame.size.width,13,20,20)];
[button setBackgroundImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
`谁能指出我哪里出错了?