I have the following code:
if (product) {
if ([product.title isStringOfInterest]) {
scriptName = [[PPLinearLayoutLabelItem alloc] initWithText:#"" font:[PPFonts bold20] maxWidth:[LayoutValues getMaxWidthClipped]];
[self.topContainerContent addObject:scriptName];
extraName = [[PPLinearLayoutLabelItem alloc] initWithText:#"" font:[PPFonts regular14] maxWidth:[LayoutValues getMaxWidthClipped]];
[scriptName setPaddingTop:20];
[self.topContainerContent addObject:extraName];
}
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void){
[self loadProductDetails];
});
-(void) loadProductDetails{
IHProduct *product = orderDisplayed.product;
id<ProductDownloadServiceProtocol> productDetailsDownloader = [[ProductDownloadService alloc] initWithClient:[[HttpClient alloc] initWith:APIbackend forEndpoint:EndpointProduct]];
[productDetailsDownloader downloadProductWithProductID:product.productID success:^(ProductDownloadResponse *response) {
scriptName.label.text = [NSString stringWithFormat:#"%# (%#)",response.product.title,response.product.pillTypeShort];
extraName.label.text = response.product.sameAs;
NSString *qtyText = [NSString stringWithFormat:#"%# PACKS (%# at $%# per pack)",[orderDisplayed.interval objectForKey:#"quantity_per_interval"], [orderDisplayed.interval objectForKey:#"quantity_per_interval"], response.product.price];
quantity.label.text = qtyText;
} error:^(ProductDownloadResponse *response) {
[self hideHttpLoadingOverlay];
[RMUniversalAlert showAlertInViewController:self
withTitle:alertErrorTitle
message:#"Error downloading mail order product details"
cancelButtonTitle:OKDialogButton
destructiveButtonTitle:nil
otherButtonTitles:nil
tapBlock:nil];
}];
}
The labels extraname and scriptname are getting filled or getting chopped off in the end i.e. incomplete data. How can I fix this? When I statically put large texts in this the data gets filled into those views nicely. Help!
If you wish adjust width of UILabel based on it text content then use below code;
NSDictionary *fontAttributes = #{NSFontAttributeName: [UIFont fontWithName:#"HelveticaNeue" size:14]};
CGRect rectOfText = [textToMeasure boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:fontAttributes
context:nil];
CGRect tempFrame = self.label.frame;
tempFrame.size.width = rectOfText.size.width;
self.label.frame = tempFrame;
And if you wish to change its font based on uilabel width then use below;
NOTE : This will work only if self.label.numberOfLines = 1.
self.label.adjustsFontSizeToFitWidth = YES;
self.label.minimumFontSize = 0;
Related
I am trying to create a custom label for coreplot using NSAttributedString. Everything works fine when my strings have 1 line.
The problem occurs when I want to have 2 line strings using code:
NSMutableAttributedString* remFinalLabel = [remAttrStr mutableCopy];
NSMutableAttributedString *newLineAttrStr = [[NSMutableAttributedString alloc]initWithString:#"\n"];
[remFinalLabel appendAttributedString:newLineAttrStr];
[remFinalLabel appendAttributedString:rem2AttrStr];
The result looks like that: not even first string is properly displayed. How can I set the number of lines in custom label?
My code to create labels:
NSMutableArray* labelsStrings = [NSMutableArray arrayWithObjects:strAttr1, strAttr2, strAttr3, nil];
NSMutableArray *ticksLocations = [NSMutableArray arrayWithObjects:#0.5, #1.5, #2.5, nil];
NSMutableArray* customLabels = [[NSMutableArray alloc] init];
NSUInteger labelLocation = 0;
#try {
for (NSNumber *tickLocation in ticksLocations) {
NSAttributedString* currentLabel = [labelsStrings objectAtIndex:labelLocation];
CPTTextLayer *txtLayer = [[CPTTextLayer alloc] initWithAttributedText:currentLabel];
CPTAxisLabel* newLabel = [[CPTAxisLabel alloc] initWithContentLayer:txtLayer];
newLabel.tickLocation = tickLocation;
newLabel.offset = 0.0f;
newLabel.alignment = CPTAlignmentLeft;
[customLabels addObject:newLabel];
labelLocation++;
}
}
#catch (NSException * e) {
DLog(#"An exception occurred while creating date labels for x-axis");
}
#finally {
y.axisLabels = [NSSet setWithArray:customLabels];
}
y.majorTickLocations = [NSSet setWithArray:ticksLocations];
You can achieve this by setting the frame of content layer of your CPTAxisLabel.
Try this:-
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:#"Your Text Here" textStyle:#"Text Style"];
[label.contentLayer setFrame:CGRectMake(0, 0, 40, 40)]; //change this frame according to your requirement
Happy Coding..!!
i can not align to the right a texview in a Custom TableViewCell.
I tried with NSTextAlignmentRight but simply doesn't work.
I adjust all the layout programmatically, maybe i forgot some checkbox to uncheck in my storyboard.
Sorry for my english, y hope you understand!
Here's my code inside cellForRowAtIndexPath:
cell = [self.tablaChat dequeueReusableCellWithIdentifier:simpleTableIdentifierUser];
if (cell == nil) {
cell = [[ChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifierUser];
}
cell.mensajeUsuario2.text = [NSString stringWithFormat:#"%#", [[self.dict_mensajes valueForKey:#"mensaje"] objectAtIndex:indexPath.row]];
NSString *dateAsString = [[self.dict_mensajes valueForKey:#"timestamp"] objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [formatter dateFromString:dateAsString];
//[self convertirFecha:date];
cell.labelUsuario2.text = [NSString stringWithFormat:#"%# el %#", [[self.dict_mensajes valueForKey:#"nombre"] objectAtIndex:indexPath.row], [self convertirFecha:date]];
cell.mensajeUsuario2.frame = CGRectMake(cell.mensajeUsuario2.frame.origin.x,
cell.mensajeUsuario2.frame.origin.y,
self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 25,
cell.mensajeUsuario2.frame.size.height);
cell.imagenUsuario2.frame = CGRectMake(self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 10,
cell.imagenUsuario2.frame.origin.y,
cell.imagenUsuario2.frame.size.width,
cell.imagenUsuario2.frame.size.height);
CGFloat fixedWidth = cell.mensajeUsuario2.frame.size.width;
CGSize newSize = [cell.mensajeUsuario2 sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = cell.mensajeUsuario2.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
cell.mensajeUsuario2.frame = newFrame;
cell.mensajeUsuario2.scrollEnabled = NO;
[cell.mensajeUsuario2.layer setBorderWidth: 1.0];
[cell.mensajeUsuario2.layer setCornerRadius:8.0f];
[cell.mensajeUsuario2.layer setMasksToBounds:YES];
alturaCelda = cell.mensajeUsuario2.frame.size.height + cell.labelUsuario2.frame.size.height;
cell.mensajeUsuario2.backgroundColor = Rgb2UIColorMediumLight(0, 0, 0);
cell.mensajeUsuario2.textColor = Rgb2UIColorMask(255, 255, 255);
cell.labelUsuario2.frame = CGRectMake(cell.labelUsuario2.frame.origin.x,
alturaCelda - 10,
self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 30,
cell.labelUsuario2.frame.size.height);
NSString *urlImagen = [NSString stringWithFormat:#"%#", [[self.dict_mensajes valueForKey:#"foto"] objectAtIndex:indexPath.row]];
NSURL *imageURL = [NSURL URLWithString:urlImagen];
UIImage *image;
// 1. Check the image cache to see if the image already exists. If so, then use it. If not, then download it.
if ([[ImageCache sharedImageCache] DoesExist:urlImagen] == true)
{
image = [[ImageCache sharedImageCache] GetImage:urlImagen];
cell.imagenUsuario2.image = image;
}
else
{
dispatch_async(kBgQueue, ^{
NSData *imgData = [NSData dataWithContentsOfURL: imageURL];
if (imgData) {
UIImage *image2 = [UIImage imageWithData:imgData];
if (image2) {
dispatch_async(dispatch_get_main_queue(), ^{
ChatTableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell)
updateCell.imagenUsuario2.image = image2;
// Add the image to the cache
[[ImageCache sharedImageCache] AddImage:urlImagen :image2];
});
}
}
});
}
[cell.mensajeUsuario2 sizeToFit];
[cell.mensajeUsuario2 layoutIfNeeded];
cell.mensajeUsuario2.textAlignment = NSTextAlignmentRight;
I solved in this way:
i moved the "cell.mensajeUsuario2.frame" declaration to the bottom and i change it to this.
cell.mensajeUsuario2.frame = CGRectMake(cell.imagenUsuario2.frame.origin.x - 10 - cell.mensajeUsuario2.frame.size.width,
cell.mensajeUsuario2.frame.origin.y,
cell.mensajeUsuario2.frame.size.width,
cell.mensajeUsuario2.frame.size.height);
How do we handle showing a http posted username to a navigation bar title? Here is a method which successfully shows a username in a jpeg represented photo taken by people in a UIScrollView*listview;
-(id)initWithIndex:(int)i andData:(NSDictionary*)data {
self = [super init];
if (self !=nil) {
//initialize
self.tag = [[data objectForKey:#"IdPhoto"] intValue];
int row = i/3;
int col = i % 3;
self.frame = CGRectMake(1.5*kPadding+col*(kThumbSide+kPadding), 1.5*kPadding+row*(kThumbSide+kPadding), kThumbSide, kThumbSide);
self.backgroundColor = [UIColor grayColor];
//add the photo caption
UILabel* caption = [[UILabel alloc] initWithFrame:CGRectMake(0, kThumbSide-16, kThumbSide, 16)];
caption.backgroundColor = [UIColor blackColor];
caption.textColor = [UIColor whiteColor];
caption.textAlignment = UITextAlignmentCenter;
caption.font = [UIFont systemFontOfSize:12];
caption.text = [NSString stringWithFormat:#"#%#",[data objectForKey:#"username"]];
[self addSubview: caption];
//add touch event
[self addTarget:delegate action:#selector(didSelectPhoto:) forControlEvents:UIControlEventTouchUpInside];
//load the image
API* api = [API sharedInstance];
int IdPhoto = [[data objectForKey:#"IdPhoto"] intValue];
NSURL* imageURL = [api urlForImageWithId:[NSNumber numberWithInt: IdPhoto] isThumb:YES];
AFImageRequestOperation* imageOperation = [AFImageRequestOperation imageRequestOperationWithRequest: [NSURLRequest requestWithURL:imageURL] success:^(UIImage *image) {
//create an image view, add it to the view
UIImageView* thumbView = [[UIImageView alloc] initWithImage: image];
thumbView.frame = CGRectMake(0,0,90,90);
thumbView.contentMode = UIViewContentModeScaleAspectFit;
[self insertSubview: thumbView belowSubview: caption];
}];
NSOperationQueue* queue = [[NSOperationQueue alloc] init];
[queue addOperation:imageOperation];
}
return self;
}
Place the self.navigationItem.title = label in the same method as the -(void)initWithIndex:(int)i andData:(NSDictionary*)data method, after the label receives information.
-(void)initWithIndex:(int)i andData:(NSDictionary*)data {
//remove the "#" from before the %# that you have below
label = [NSString stringWithFormat:#"#%#",[data objectForKey:#"username"]];
self.navigationItem.title = label;
}
Depending on whether it needs to load immediately, you should call the -(void)initWithIndex:(int)i andData:(NSDictionary*)data in viewDidLoad or viewWillAppear methods.
UPDATE
Try using this:
[self.navigationItem setTitle: label];
For some reason this works better. I tried both in a test and this one worked for me over the other.
UPDATE 2
Initialise your label with a value/object.
-(void)viewDidLoad{
label = #"";//initialises the value to be a blank string enabling use
//call your method that assigns the title now.
}
Now when the method -(void)initWithIndex:(int)i andData:(NSDictionary*)data is called, the title should update as label has been initialised and will now update it's value.
UPDATE 3 - AS PER ASKERS REQUEST
At the top of .m file
#interface YourClassName ()
{
NSString * label;
}
#end
#implementation YourClassName
-(void)viewDidLoad{
label = #"";//initialises the value to be a blank string enabling use
}
-(void)initWithIndex:(int)i andData:(NSDictionary*)data {
//remove the "#" from before the %# that you have below
label = [NSString stringWithFormat:#"#%#",[data objectForKey:#"username"]];
//the label now has a new value so use it for title
self.navigationItem.title = label;
//test to see that there is a value available in log
NSLog(#"What is the name: %#", label);
}
I have a custom UILabel that I download from Github (called KILabel). The reason I got it because I wanted to duplicate Instagram's activity feed(The segmented control and the UITableViews with 2 different sets of information). In instagram's app I know there is the ability to tap on people usernames within the label that is contained in each and ever UITableViewCell(This is where KILabel comes into play). KILabel recognizes "#usernames", "#hashtags", and URLs and makes them tappable almost like a UIButton.
I had previously went without the KILabel and used the regular UILabel and it was able to expand in iOS 8 and iOS 7. Now, when I use the KILabel it auto expands(Dynamically changes its height to fit the text) ONLY on iOS 7 and it does NOT start off expanded. When I scroll in my UITableViewController, that is when the label expands. It starts off normal height.
As of right now this what the Custom Cell looks like
#import <UIKit/UIKit.h>
#import "KILabel.h"
#interface NewsCell : UITableViewCell
#property (strong, nonatomic) IBOutlet KILabel *cellLabel;
#property (strong, nonatomic) IBOutlet UIImageView *cellImageView;
#end
I have the label in the interface(storyboard) hooked up to the custom KILabel class as well as the ImageView.
Next I have the cell being implemented in the UITableViewController. I tested it with a large piece of text to see if the cell and label would expand to the correct size
cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier2 forIndexPath:indexPath];
cell.cellImageView.layer.cornerRadius = 6.0f;
cell.cellImageView.clipsToBounds = YES;
cell.cellImageView.layer.borderWidth = 1.0f;
cell.cellImageView.layer.borderColor = [[UIColor blackColor] CGColor];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] init];
longPress.numberOfTapsRequired = 1;
[cell.cellLabel addGestureRecognizer:longPress];
//Create the cell label going into the cell
cell.cellLabel.linkTapHandler = ^(KILinkType linkType, NSString *string, NSRange range) {
NSString *mString = [string stringByReplacingOccurrencesOfString:#"#" withString:#""];
if (linkType == KILinkTypeURL) {
// Open URLs
//[self attemptOpenURL:[NSURL URLWithString:string]];
} else if (linkType == KILinkTypeUserHandle) {
if (longPress.state == UIGestureRecognizerStatePossible) {
[self tapOnUsername:longPress username:mString];
}
} else {
// Put up an alert with a message if it's not an URL
NSString *linkTypeString = #"Username";
if (linkType == KILinkTypeHashtag)
{
linkTypeString = #"Hashtag";
}
NSString *message = [NSString stringWithFormat:#"You tapped %# which is a %#", string, linkTypeString];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello"
message:message
delegate:nil
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[alert show];
}
};
PFObject *eachNews = [self.followingNews objectAtIndex:indexPath.row];
PFUser *notifier = [eachNews objectForKey:#"Notifier"];
PFUser *notified = [eachNews objectForKey:#"Notified"];
[notifier fetchIfNeeded];
[notified fetchIfNeeded];
NSString *notifierString = [[NSString alloc] init];
NSString *notifiedString = [[NSString alloc] init];
NSString *grammer = [[NSString alloc] init];
NSDate *timeStamp = eachNews.createdAt;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"MMM d, yyyy h:mm a"];
NSString *timeString = [timeStamp formattedAsTimeAgo];
if ([notifier.username isEqualToString:_loggedInUser.username]) {
notifierString = #"You";
grammer = #"are";
} else {
notifierString = [NSString stringWithFormat:#"#%#", notifier.username];
grammer = #"is";
}
if ([notified.username isEqualToString: _loggedInUser.username]) {
notifiedString = #"you";
} else {
notifiedString = [NSString stringWithFormat:#"#%#", notified.username];
}
if (notifier[#"profileImage"] == nil) {
UIImage *hermet = [UIImage imageNamed:#"user"];
[cell.cellImageView setImage:hermet];
} else {
PFFile *imageFile = notifier[#"profileImage"];
[cell.cellImageView setImage:[UIImage imageWithData:[imageFile getData]]];
}
NSMutableString *newsText = [[NSMutableString alloc] init];
if ([eachNews[#"Type"] isEqualToString:#"Follow"]) {
[newsText appendString:[NSString stringWithFormat:#"%# aaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUVaaaaaaaaaaaaaaasdasafsfsdgsdgsdfgsdfsodjnfsaioefgnarpuoigbweuifbsdpugbdsfiougbsdiugosbdgiusobfasdioFPBSADUBVSIUDVBSAIUDBSDIUVBSDUVIBDSFIUVBSDIUVSBAVIPUBDSIUV%# %#.\n", notifierString, eachNews[#"Messages"], notifiedString]];
} else if ([eachNews[#"Type"] isEqualToString:#"New Founder"]) {
[newsText appendString:[NSString stringWithFormat:#"%# %# %#.\n", notifierString, grammer, eachNews[#"Messages"]]];
} else if ([eachNews[#"Type"] isEqualToString:#"Club Create"]) {
if([notified.username isEqualToString:_loggedInUser.username]) {
notifiedString = #"You";
} else {
notifiedString = notified.username;
}
if (notified[#"profileImage"] == nil) {
UIImage *hermet = [UIImage imageNamed:#"user"];
[cell.cellImageView setImage:hermet];
} else {
PFFile *imageFile = notified[#"profileImage"];
[cell.cellImageView setImage:[UIImage imageWithData:[imageFile getData]]];
}
[newsText appendString:[NSString stringWithFormat:#"%# %#\n", notifiedString, eachNews[#"Messages"]]];
}
[newsText appendString:timeString];
NSArray *appendedString = [newsText componentsSeparatedByString:#"\n"];
NSRange dateRange = [newsText rangeOfString:appendedString[1]];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:newsText];
[attrString beginEditing];
[attrString addAttribute: NSForegroundColorAttributeName
value:[UIColor lightGrayColor]
range:dateRange];
[attrString endEditing];
cell.cellLabel.attributedText = attrString;
CGSize sizeForLabel = CGSizeMake(cell.cellLabel.frame.size.width, 0);
CGRect labelRect = CGRectMake(cell.cellLabel.frame.origin.x, cell.cellLabel.frame.origin.y, sizeForLabel.width, CGFLOAT_MAX);
// Use a dummy label and its textRectForBounds method to calculate the height
// of a real label.
KILabel *measureLabel = [[KILabel alloc] initWithFrame:CGRectMake(cell.cellLabel.frame.origin.x, cell.cellLabel.frame.origin.y, labelRect.size.width, 0)];
measureLabel.numberOfLines = 0;
measureLabel.attributedText = attrString;
labelRect = [measureLabel textRectForBounds:labelRect limitedToNumberOfLines:0];
cell.cellLabel.frame = labelRect;
The height of UITableViewCell is completely fine and expands perfectly. The label is the only issues. It does not expand at all on iOS 8 and expands ONLY AFTER I have scrolled in the UITableViewController on iOS 7.
I would tagged KILabel but I can't and if anyone has used another UILabels like KILabel and been able to get them auto-expand please refer me to them.
KILabel on GitHub: https://github.com/Krelborn/KILabel
Also, I have already tried the Gist the creator posted on his GitHub and that will get my cell to expand perfectly.
In my ios app
im rendering html tags
using
DTAttributedTextView
this is the rest of the coding structure
//create the custom label to get positions
UILabel *customLabel = [[UILabel alloc]initWithFrame:CGRectMake(lblContent.frame.origin.x, lblContent.frame.origin.y,lblContent.frame.size.width,lblContent.frame.size.height)];
customLabel.text = _artistDetail.strContent;
customLabel.numberOfLines = 0;
[customLabel sizeToFit];
[lblContent removeFromSuperview];
CGRect frame = CGRectMake(customLabel.frame.origin.x, customLabel.frame.origin.y,customLabel.frame.size.width,500);
NSString *htmlText = HTML_DIV_TAG;
htmlText = [htmlText stringByAppendingFormat:#"%#%#",_artistDetail.strContent,#"</div>"];
htmlText = [htmlText stringByReplacingOccurrencesOfString:#"''" withString:#"'"];
NSData *data = [htmlText dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTML:data options:nil documentAttributes:NULL];
[DTAttributedTextContentView setLayerClass:[CATiledLayer class]];
DTAttributedTextView *_textView = [[DTAttributedTextView alloc] initWithFrame:frame];
_textView.textDelegate = self;
_textView.attributedString = string;
[_textView sizeToFit];
_textView.autoresizesSubviews = YES;
[self.contentView addSubview:_textView];
Now i want to increas the label according to the content height
Is thr any way to do it
Thanks
Have you tried something like:
[DTAttributedTextContentView setLayerClass:[CATiledLayer class]];
DTAttributedTextView *_textView = [[DTAttributedTextView alloc] initWithFrame:frame];
_textView.textDelegate = self;
_textView.attributedString = string;
CGRect frame = _textView.frame;
CGSize size = _textView.contentSize;
frame.size.height = size.height;
_textView.frame = frame;
[self.contentView addSubview:_textView];