我有一个视图,它在最左边有一个标签,然后是一个带有用户名的按钮,然后是他在右边按钮后面的评论。我想要做的是将标签放置在 UIButton 文本结束的位置。在这种情况下,如果用户名是长或短,评论将开始,用户名按钮和评论标签之间没有任何空格。我目前正在像这样进行硬编码,如何根据 UIButtion 的文本大小实现 UILabel 的动态位置?,PfButton 是 UIButton 的子类 谢谢
PfButton *button = [PfButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:name forState:UIControlStateNormal];
[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[button setContentEdgeInsets:UIEdgeInsetsMake(0, 13, 0, 0)];
[button setObjectId:objId];
[button addTarget:self action:@selector(profilePhotoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(30, -7, 130, 20)];
[[button titleLabel] setTextAlignment:NSTextAlignmentLeft];
[view addSubview:button];
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, -7, 150, 20)];
[messageLabel setFont:[UIFont systemFontOfSize:15]];
[messageLabel setText:msg];
[messageLabel setTextAlignment:NSTextAlignmentLeft];
[view addSubview:messageLabel];
[messageLabel release];