I have a view which has a label on extreme left, then a button with username and then his comment after the button on the right. What I want to do is to position Label where text of UIButton is ending. In this case, if username is long or short, comment will start without any space between the username button and comment label. I am currently doing hard coded like this, how can I achieve dynamic position of UILabel depending upon size of text of UIButtion?, PfButton is subclass of UIButton Thanks
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];
titleLabel
is aUIView
subclass. You can get its frame. Use that to position your other label. – KDaker