Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimumSize #43

Open
mladjan opened this issue Jul 22, 2013 · 3 comments
Open

optimumSize #43

mladjan opened this issue Jul 22, 2013 · 3 comments

Comments

@mladjan
Copy link

mladjan commented Jul 22, 2013

optimumSize crashes, with: code=EXC_ARM_BREAKPOINT, subcode=0xdefe

label content is: "ENERGIEWENDE IN DEUTSCHLAND"
Here is the code (sorry for junk code):

           RTLabel *tv = [[RTLabel alloc] init];
                if([contentElement attributeNamed:@"line-height"]){
                    [tv setLineSpacing:[[contentElement attributeNamed:@"line-height"] floatValue]];
                }
                [tv setText:[contentElement value]];
                if([contentElement attributeNamed:@"line-height"]){
                    [tv setLineSpacing:[[contentElement attributeNamed:@"line-height"] floatValue]];
                }
                [tv setTag:[[contentElement attributeNamed:@"id"] intValue]];
                [tv setTranslatesAutoresizingMaskIntoConstraints:NO];

                UIFont *font;
                if(fontName && [contentElement attributeNamed:@"size"]){
                    font = [UIFont fontWithName:fontName size:[[contentElement attributeNamed:@"size"] intValue]];
                }else{
                    font = [UIFont fontWithName:fontName size:16];
                }
                [tv setFont:font];

                if([[contentElement attributeNamed:@"align"] isEqualToString:@"left"]){
                    tv.textAlignment = NSTextAlignmentLeft;
                }else if([[contentElement attributeNamed:@"align"] isEqualToString:@"right"]){
                    tv.textAlignment = NSTextAlignmentRight;
                }else{
                    tv.textAlignment = NSTextAlignmentLeft;
                }
                if([contentElement attributeNamed:@"color"]){
                    unsigned result = 0;
                    NSScanner *scanner = [NSScanner scannerWithString:[contentElement attributeNamed:@"color"]];
                    [scanner scanHexInt:&result];
                    UIColor *color = UIColorFromRGB(result);
                    if(invertedColors){
                        [tv setTextColor:[color inverseColor]];
                    }else{
                        [tv setTextColor:color];
                    }
                }else{
                    if(invertedColors){
                        [tv setTextColor:[UIColor whiteColor]];
                    }else{
                        [tv setTextColor:[UIColor blackColor]];
                    }
                }

                [tv setBackgroundColor:[UIColor clearColor]];
                tv.lineBreakMode = NSLineBreakByWordWrapping; // or some other desired wrapping

                if(width == 350){
                    CGRect frame = CGRectMake(0, 0, 350 - [[pageContent attributeNamed:@"margin"] floatValue], 9999); // oversized height
                    tv.frame = frame;
                }else{
                    CGRect frame = CGRectMake(0, 0, 1024, 9999); // oversized height
                    tv.frame = frame;
                }


                [containerView addSubview:tv];
                CGSize optimumSize = [tv optimumSize];
@amitbattan
Copy link

I am also facing same problem. have to found any solution

@adnanbajwa
Copy link

I had the same issue, found solution after initialization of RTlLabel with frame of height 100.

RTLabel *yourLabel = [[RTLabel alloc] initWithFrame:CGRectMake(0,0,100,100)];
then assign text n get optimize height and update frame of yourLabel.

@sysail
Copy link

sysail commented Oct 12, 2022

Same problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants