so i have problems to calculate UIlabel text height after passing it to another window/viewcontrollers
heres my code to passing
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NetraDealsObject *dataObject=[self.deals_data_json objectAtIndex:indexPath.row];
detailViewController = [[MJDetailViewController alloc] initWithNibName:@"MJDetailViewController" bundle:nil];
[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideBottomBottom];
detailViewController.NetraPopupPrice.text=dataObject.formatted;
}
for example the text==123;
and here the detailviewController
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
NetraPopupPrice=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NetraPopupPrice.backgroundColor=[UIColor colorWithRed:0.31 green:0.733 blue:0 alpha:1]; /*#4fbb00*/
NetraPopupPrice.textColor=[UIColor whiteColor];
NetraPopupPrice.textAlignment=NSTextAlignmentCenter;
NetraPopupPrice.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:18];
[NetraPopupPrice.layer setCornerRadius:3];
NetraPopupProvider=[[UILabel alloc] initWithFrame:CGRectMake(135.0f, 55, 80, 16)];
NetraPopupProvider.backgroundColor=[UIColor clearColor];
NetraPopupProvider.textColor=[UIColor colorWithRed:0.769 green:0.776 blue:0.788 alpha:1];
NetraPopupProvider.font=[UIFont fontWithName:@"Helvetica" size:13];
//separator
NetraPopupSeparator=[[UILabel alloc] initWithFrame:CGRectMake(215,55.0f, 80, 16)];
NetraPopupSeparator.text=@"-",
NetraPopupSeparator.backgroundColor=[UIColor clearColor];
NetraPopupSeparator.textColor=[UIColor colorWithRed:0.769 green:0.776 blue:0.788 alpha:1];
NetraPopupSeparator.font=[UIFont fontWithName:@"Helvetica" size:13];
//
//separator
NetraPopupLocation=[[UILabel alloc] initWithFrame:CGRectMake(225, 55.0f, 70, 16)];
NetraPopupLocation.backgroundColor=[UIColor clearColor];
NetraPopupLocation.textColor=[UIColor colorWithRed:0.769 green:0.776 blue:0.788 alpha:1];
NetraPopupLocation.font=[UIFont fontWithName:@"Helvetica" size:13];
NetraPopupHeadline=[[UILabel alloc] init];
NetraPopupHeadline.textColor=[UIColor colorWithRed:0.227 green:0.243 blue:0.247 alpha:1];
NetraPopupHeadline.lineBreakMode=NSLineBreakByCharWrapping;
NetraPopupHeadline.backgroundColor=[UIColor redColor];
NetraPopupHeadline.numberOfLines=0;
NetraPopupHeadline.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:13];
}
[[self view] addSubview:NetraPopupPrice];
[[self view] addSubview:NetraPopupProvider];
[[self view] addSubview:NetraPopupSeparator];
[[self view] addSubview:NetraPopupLocation];
[[self view] addSubview:NetraPopupHeadline];
return self;
}
-(void)viewDidLoad{
[super viewDidLoad];
CGSize NetraLabelForPriceWidth = [[NetraPopupPrice text] sizeWithFont:[NetraPopupPrice font]];
CGFloat NetraLabelForPriceW = NetraLabelForPriceWidth.width;
NSLog(@"Width=%f",NetraLabelForPriceW);
}
-(void)viewWillAppear:(BOOL)animated{
}
- (void)viewDidUnload {
[super viewDidUnload];
}
@end
and the result when log it
NSLog(@"Width=%f",NetraLabelForPriceW);
is:
[9858:19d03] Width=0.000000
it should be calculate right? anything wrong in my code?
Try logging the address of your
NetraPopupPriceand its text in viewDidLoad. Also try “adding to Subview” inside theif(self)block of initWithNibName.