I have been following several Q/A aboit this: like this and this other one.
However I am unable to change the width of a UILabel.
Here is my code:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
Data *detailData = (Data*)self.detailItem;
NSString * priceString = [NSString stringWithFormat:@"%@ %.2f", detailData.priceCurrency, detailData.priceAmount.floatValue ];
CGSize size = [priceString sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]}];
CGSize adjustedSize = CGSizeMake(ceilf(size.width), ceilf(size.height));
_price.frame = CGRectMake(_price.frame.origin.x, _price.frame.origin.y, 300, adjustedSize.height);
// I Tried this one as well..
//_price.frame = CGRectMake(_price.frame.origin.x, _price.frame.origin.y, adjustedSize.width, adjustedSize.height);
_price.text = priceString;
// and this one
// [_price sizeToFit];
// And this one
[_price setFrame:CGRectMake(_price.frame.origin.x,_price.frame.origin.y,adjustedSize.width,adjustedSize.height)];
[_price setText:priceString];
// as well as hardocding the width to 300
// [_price setFrame:CGRectMake(_price.frame.origin.x,_price.frame.origin.y,300,adjustedSize.height)];
}
}
Unfortunately none of the above changes the width UILabel.
This is how I set it up in Interface builder, is there something wrong here? The original width is 40 so by hardcoding it to 300 I expected it to change.
The view is a DetailView which is accessed from a MasterViewController when the user taps on a cel. This is the code on DetailViewController that I use to call the configureView method described above.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
Any idea on what I could be missing?
This is how I initialize my outlets:
// DetailViewController.m
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize price = _price;
The good thing is that the text content is there so the outlet references are not nil.
However this is how the UILabel appears:
EDIT:
I tried to remove the constraints but it seems to be still not effective.
This is the code now:
_price.frame = CGRectMake(_price.frame.origin.x, _price.frame.origin.y, 300, 200);
_price.text = @"bdadadsdsdsdsDsds";