content does not fit on to the UI label
-(void) genResultView :(UIScrollView *) scroller mainView :(float) labelTextSize :(float) textViewTxtSize;
{
float imageViewW;
float imageViewH;
float padding;
float labelH;
float labelW;
float textViewH;
float textViewW;
float lineH = 2.0f;
float lineW;
float titleFontSize;
NSString *font = @"Georgia";
UIColor *fontColour = [UIColor whiteColor];
//make instances of objects here
leftCharacterImage = [[UIImageView alloc]init];
rightCharacterImage = [[UIImageView alloc]init];
leftNameLabel = [[UILabel alloc]init];
rightNameLabel = [[UILabel alloc]init];
leftGenderLabel = [[UILabel alloc]init];
rightGenderLabel = [[UILabel alloc]init];
leftPerType = [[UILabel alloc]init];
rightPerType = [[UILabel alloc]init];
vsLabel = [[UILabel alloc]init];
compareText = [[UILabel alloc]init];
mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scroller.frame.size.width, scroller.frame.size.height)];
//Set frame & font sizes here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
padding = 25;
imageViewH = 90;
imageViewW = 90;
textViewH = 250;
textViewW = 280;
labelH = 30;
labelW = 100;
lineW = 300;
titleFontSize = 11;
} else {
padding = 50;
imageViewH = 200;
imageViewW = 200;
textViewH = 500;
textViewW = 1000;
labelH = 30;
labelW = 200;
lineW = 700;
titleFontSize = 20;
}
//Set control sizes & locations
//set imageview frames
leftCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2-imageViewW, padding+lineH, imageViewW,imageViewH);
rightCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2+imageViewW, padding+lineH,imageViewW ,imageViewH);
//set label frames & text sizes
[vsLabel setTextAlignment:NSTextAlignmentJustified];
[vsLabel setFont:[UIFont fontWithName: @"Georgia-bold" size:titleFontSize]];
[vsLabel setTextColor:fontColour];
// vsLabel.numberOfLines = 0;
leftNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH +imageViewH,labelW ,labelH);
[leftNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftNameLabel setTextColor:fontColour];
rightNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH,labelW ,labelH);
[rightNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightNameLabel setTextColor:fontColour];
leftGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH,labelW ,labelH);
[leftGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftGenderLabel setTextColor:fontColour];
rightGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH ,labelW ,labelH);
[rightGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightGenderLabel setTextColor:fontColour];
leftPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH + labelH,labelW ,labelH);
[leftPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftPerType setTextColor:fontColour];
rightPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH * 2,labelW ,labelH);
[rightPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightPerType setTextColor:fontColour];
line2 = [[UIImageView alloc]init];
line2.frame = CGRectMake(mainView.frame.size.width/2-lineW/2, padding + lineH + imageViewH + labelH * 3 + 10, lineW,lineH);
[line2 setBackgroundColor:[UIColor whiteColor]];
[mainView addSubview:line2];
vsLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH * 3 + 25,(imageViewW + labelW *2)+10,labelH);
//set text view frame
compareText.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + imageViewH + labelH * 3 + vsLabel.frame.size.height + 50,textViewW ,textViewH);
[compareText setFont:[UIFont fontWithName: font size:textViewTxtSize]];
//
[compareText setTextColor:fontColour];
[compareText setBackgroundColor:[UIColor clearColor]];
compareText.numberOfLines = 0;
//add to mainview
[mainView addSubview:leftCharacterImage];
[mainView addSubview:rightCharacterImage];
[mainView addSubview:vsLabel];
[mainView addSubview:leftNameLabel];
[mainView addSubview:rightNameLabel];
[mainView addSubview:leftGenderLabel];
[mainView addSubview:rightGenderLabel];
[mainView addSubview:leftPerType];
[mainView addSubview:rightPerType];
[mainView addSubview:compareText];
//call compareResult
[self genCompareResult];
[tfcompareDescription boldHeadings:compareDescription :[UIFont fontWithName:@"Georgia-bold" size:20.0] :[UIFont fontWithName:@"Georgia" size:10.0]:compareText :tfcompareDescription.listOfRanges];
[compareText setTextAlignment:NSTextAlignmentJustified];
[vsLabel setText:[NSString stringWithFormat:@"Tips for %@ and %@ to work together more effectively:",characterType1,characterType2]];
[compareText sizeToFit];
[vsLabel sizeToFit];
mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);
[scroller addSubview:mainView];
}
I just want to show some data on UILabel when the code run it shows like that.I just want show the data fit on to the Ui label regardless of the device. What I want to do is I just want to keep the font line steady and change the label size according to the no of line in the description
enter image description here
ios objective-c
add a comment |
-(void) genResultView :(UIScrollView *) scroller mainView :(float) labelTextSize :(float) textViewTxtSize;
{
float imageViewW;
float imageViewH;
float padding;
float labelH;
float labelW;
float textViewH;
float textViewW;
float lineH = 2.0f;
float lineW;
float titleFontSize;
NSString *font = @"Georgia";
UIColor *fontColour = [UIColor whiteColor];
//make instances of objects here
leftCharacterImage = [[UIImageView alloc]init];
rightCharacterImage = [[UIImageView alloc]init];
leftNameLabel = [[UILabel alloc]init];
rightNameLabel = [[UILabel alloc]init];
leftGenderLabel = [[UILabel alloc]init];
rightGenderLabel = [[UILabel alloc]init];
leftPerType = [[UILabel alloc]init];
rightPerType = [[UILabel alloc]init];
vsLabel = [[UILabel alloc]init];
compareText = [[UILabel alloc]init];
mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scroller.frame.size.width, scroller.frame.size.height)];
//Set frame & font sizes here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
padding = 25;
imageViewH = 90;
imageViewW = 90;
textViewH = 250;
textViewW = 280;
labelH = 30;
labelW = 100;
lineW = 300;
titleFontSize = 11;
} else {
padding = 50;
imageViewH = 200;
imageViewW = 200;
textViewH = 500;
textViewW = 1000;
labelH = 30;
labelW = 200;
lineW = 700;
titleFontSize = 20;
}
//Set control sizes & locations
//set imageview frames
leftCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2-imageViewW, padding+lineH, imageViewW,imageViewH);
rightCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2+imageViewW, padding+lineH,imageViewW ,imageViewH);
//set label frames & text sizes
[vsLabel setTextAlignment:NSTextAlignmentJustified];
[vsLabel setFont:[UIFont fontWithName: @"Georgia-bold" size:titleFontSize]];
[vsLabel setTextColor:fontColour];
// vsLabel.numberOfLines = 0;
leftNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH +imageViewH,labelW ,labelH);
[leftNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftNameLabel setTextColor:fontColour];
rightNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH,labelW ,labelH);
[rightNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightNameLabel setTextColor:fontColour];
leftGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH,labelW ,labelH);
[leftGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftGenderLabel setTextColor:fontColour];
rightGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH ,labelW ,labelH);
[rightGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightGenderLabel setTextColor:fontColour];
leftPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH + labelH,labelW ,labelH);
[leftPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftPerType setTextColor:fontColour];
rightPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH * 2,labelW ,labelH);
[rightPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightPerType setTextColor:fontColour];
line2 = [[UIImageView alloc]init];
line2.frame = CGRectMake(mainView.frame.size.width/2-lineW/2, padding + lineH + imageViewH + labelH * 3 + 10, lineW,lineH);
[line2 setBackgroundColor:[UIColor whiteColor]];
[mainView addSubview:line2];
vsLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH * 3 + 25,(imageViewW + labelW *2)+10,labelH);
//set text view frame
compareText.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + imageViewH + labelH * 3 + vsLabel.frame.size.height + 50,textViewW ,textViewH);
[compareText setFont:[UIFont fontWithName: font size:textViewTxtSize]];
//
[compareText setTextColor:fontColour];
[compareText setBackgroundColor:[UIColor clearColor]];
compareText.numberOfLines = 0;
//add to mainview
[mainView addSubview:leftCharacterImage];
[mainView addSubview:rightCharacterImage];
[mainView addSubview:vsLabel];
[mainView addSubview:leftNameLabel];
[mainView addSubview:rightNameLabel];
[mainView addSubview:leftGenderLabel];
[mainView addSubview:rightGenderLabel];
[mainView addSubview:leftPerType];
[mainView addSubview:rightPerType];
[mainView addSubview:compareText];
//call compareResult
[self genCompareResult];
[tfcompareDescription boldHeadings:compareDescription :[UIFont fontWithName:@"Georgia-bold" size:20.0] :[UIFont fontWithName:@"Georgia" size:10.0]:compareText :tfcompareDescription.listOfRanges];
[compareText setTextAlignment:NSTextAlignmentJustified];
[vsLabel setText:[NSString stringWithFormat:@"Tips for %@ and %@ to work together more effectively:",characterType1,characterType2]];
[compareText sizeToFit];
[vsLabel sizeToFit];
mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);
[scroller addSubview:mainView];
}
I just want to show some data on UILabel when the code run it shows like that.I just want show the data fit on to the Ui label regardless of the device. What I want to do is I just want to keep the font line steady and change the label size according to the no of line in the description
enter image description here
ios objective-c
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fitmainView
.. so I suspect the calculations are incorrect.
– Brandon
Nov 21 '18 at 1:13
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07
add a comment |
-(void) genResultView :(UIScrollView *) scroller mainView :(float) labelTextSize :(float) textViewTxtSize;
{
float imageViewW;
float imageViewH;
float padding;
float labelH;
float labelW;
float textViewH;
float textViewW;
float lineH = 2.0f;
float lineW;
float titleFontSize;
NSString *font = @"Georgia";
UIColor *fontColour = [UIColor whiteColor];
//make instances of objects here
leftCharacterImage = [[UIImageView alloc]init];
rightCharacterImage = [[UIImageView alloc]init];
leftNameLabel = [[UILabel alloc]init];
rightNameLabel = [[UILabel alloc]init];
leftGenderLabel = [[UILabel alloc]init];
rightGenderLabel = [[UILabel alloc]init];
leftPerType = [[UILabel alloc]init];
rightPerType = [[UILabel alloc]init];
vsLabel = [[UILabel alloc]init];
compareText = [[UILabel alloc]init];
mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scroller.frame.size.width, scroller.frame.size.height)];
//Set frame & font sizes here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
padding = 25;
imageViewH = 90;
imageViewW = 90;
textViewH = 250;
textViewW = 280;
labelH = 30;
labelW = 100;
lineW = 300;
titleFontSize = 11;
} else {
padding = 50;
imageViewH = 200;
imageViewW = 200;
textViewH = 500;
textViewW = 1000;
labelH = 30;
labelW = 200;
lineW = 700;
titleFontSize = 20;
}
//Set control sizes & locations
//set imageview frames
leftCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2-imageViewW, padding+lineH, imageViewW,imageViewH);
rightCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2+imageViewW, padding+lineH,imageViewW ,imageViewH);
//set label frames & text sizes
[vsLabel setTextAlignment:NSTextAlignmentJustified];
[vsLabel setFont:[UIFont fontWithName: @"Georgia-bold" size:titleFontSize]];
[vsLabel setTextColor:fontColour];
// vsLabel.numberOfLines = 0;
leftNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH +imageViewH,labelW ,labelH);
[leftNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftNameLabel setTextColor:fontColour];
rightNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH,labelW ,labelH);
[rightNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightNameLabel setTextColor:fontColour];
leftGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH,labelW ,labelH);
[leftGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftGenderLabel setTextColor:fontColour];
rightGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH ,labelW ,labelH);
[rightGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightGenderLabel setTextColor:fontColour];
leftPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH + labelH,labelW ,labelH);
[leftPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftPerType setTextColor:fontColour];
rightPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH * 2,labelW ,labelH);
[rightPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightPerType setTextColor:fontColour];
line2 = [[UIImageView alloc]init];
line2.frame = CGRectMake(mainView.frame.size.width/2-lineW/2, padding + lineH + imageViewH + labelH * 3 + 10, lineW,lineH);
[line2 setBackgroundColor:[UIColor whiteColor]];
[mainView addSubview:line2];
vsLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH * 3 + 25,(imageViewW + labelW *2)+10,labelH);
//set text view frame
compareText.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + imageViewH + labelH * 3 + vsLabel.frame.size.height + 50,textViewW ,textViewH);
[compareText setFont:[UIFont fontWithName: font size:textViewTxtSize]];
//
[compareText setTextColor:fontColour];
[compareText setBackgroundColor:[UIColor clearColor]];
compareText.numberOfLines = 0;
//add to mainview
[mainView addSubview:leftCharacterImage];
[mainView addSubview:rightCharacterImage];
[mainView addSubview:vsLabel];
[mainView addSubview:leftNameLabel];
[mainView addSubview:rightNameLabel];
[mainView addSubview:leftGenderLabel];
[mainView addSubview:rightGenderLabel];
[mainView addSubview:leftPerType];
[mainView addSubview:rightPerType];
[mainView addSubview:compareText];
//call compareResult
[self genCompareResult];
[tfcompareDescription boldHeadings:compareDescription :[UIFont fontWithName:@"Georgia-bold" size:20.0] :[UIFont fontWithName:@"Georgia" size:10.0]:compareText :tfcompareDescription.listOfRanges];
[compareText setTextAlignment:NSTextAlignmentJustified];
[vsLabel setText:[NSString stringWithFormat:@"Tips for %@ and %@ to work together more effectively:",characterType1,characterType2]];
[compareText sizeToFit];
[vsLabel sizeToFit];
mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);
[scroller addSubview:mainView];
}
I just want to show some data on UILabel when the code run it shows like that.I just want show the data fit on to the Ui label regardless of the device. What I want to do is I just want to keep the font line steady and change the label size according to the no of line in the description
enter image description here
ios objective-c
-(void) genResultView :(UIScrollView *) scroller mainView :(float) labelTextSize :(float) textViewTxtSize;
{
float imageViewW;
float imageViewH;
float padding;
float labelH;
float labelW;
float textViewH;
float textViewW;
float lineH = 2.0f;
float lineW;
float titleFontSize;
NSString *font = @"Georgia";
UIColor *fontColour = [UIColor whiteColor];
//make instances of objects here
leftCharacterImage = [[UIImageView alloc]init];
rightCharacterImage = [[UIImageView alloc]init];
leftNameLabel = [[UILabel alloc]init];
rightNameLabel = [[UILabel alloc]init];
leftGenderLabel = [[UILabel alloc]init];
rightGenderLabel = [[UILabel alloc]init];
leftPerType = [[UILabel alloc]init];
rightPerType = [[UILabel alloc]init];
vsLabel = [[UILabel alloc]init];
compareText = [[UILabel alloc]init];
mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scroller.frame.size.width, scroller.frame.size.height)];
//Set frame & font sizes here
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
padding = 25;
imageViewH = 90;
imageViewW = 90;
textViewH = 250;
textViewW = 280;
labelH = 30;
labelW = 100;
lineW = 300;
titleFontSize = 11;
} else {
padding = 50;
imageViewH = 200;
imageViewW = 200;
textViewH = 500;
textViewW = 1000;
labelH = 30;
labelW = 200;
lineW = 700;
titleFontSize = 20;
}
//Set control sizes & locations
//set imageview frames
leftCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2-imageViewW, padding+lineH, imageViewW,imageViewH);
rightCharacterImage.frame = CGRectMake(mainView.frame.size.width/2-imageViewW/2+imageViewW, padding+lineH,imageViewW ,imageViewH);
//set label frames & text sizes
[vsLabel setTextAlignment:NSTextAlignmentJustified];
[vsLabel setFont:[UIFont fontWithName: @"Georgia-bold" size:titleFontSize]];
[vsLabel setTextColor:fontColour];
// vsLabel.numberOfLines = 0;
leftNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH +imageViewH,labelW ,labelH);
[leftNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftNameLabel setTextColor:fontColour];
rightNameLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH,labelW ,labelH);
[rightNameLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightNameLabel setTextColor:fontColour];
leftGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH,labelW ,labelH);
[leftGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftGenderLabel setTextColor:fontColour];
rightGenderLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH ,labelW ,labelH);
[rightGenderLabel setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightGenderLabel setTextColor:fontColour];
leftPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH + labelH,labelW ,labelH);
[leftPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[leftPerType setTextColor:fontColour];
rightPerType.frame = CGRectMake(mainView.frame.size.width/2-labelW+imageViewW, padding + lineH + imageViewH + labelH * 2,labelW ,labelH);
[rightPerType setFont:[UIFont fontWithName: font size:labelTextSize]];
[rightPerType setTextColor:fontColour];
line2 = [[UIImageView alloc]init];
line2.frame = CGRectMake(mainView.frame.size.width/2-lineW/2, padding + lineH + imageViewH + labelH * 3 + 10, lineW,lineH);
[line2 setBackgroundColor:[UIColor whiteColor]];
[mainView addSubview:line2];
vsLabel.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + lineH + imageViewH + labelH * 3 + 25,(imageViewW + labelW *2)+10,labelH);
//set text view frame
compareText.frame = CGRectMake(mainView.frame.size.width/2-labelW/2-imageViewW, padding + imageViewH + labelH * 3 + vsLabel.frame.size.height + 50,textViewW ,textViewH);
[compareText setFont:[UIFont fontWithName: font size:textViewTxtSize]];
//
[compareText setTextColor:fontColour];
[compareText setBackgroundColor:[UIColor clearColor]];
compareText.numberOfLines = 0;
//add to mainview
[mainView addSubview:leftCharacterImage];
[mainView addSubview:rightCharacterImage];
[mainView addSubview:vsLabel];
[mainView addSubview:leftNameLabel];
[mainView addSubview:rightNameLabel];
[mainView addSubview:leftGenderLabel];
[mainView addSubview:rightGenderLabel];
[mainView addSubview:leftPerType];
[mainView addSubview:rightPerType];
[mainView addSubview:compareText];
//call compareResult
[self genCompareResult];
[tfcompareDescription boldHeadings:compareDescription :[UIFont fontWithName:@"Georgia-bold" size:20.0] :[UIFont fontWithName:@"Georgia" size:10.0]:compareText :tfcompareDescription.listOfRanges];
[compareText setTextAlignment:NSTextAlignmentJustified];
[vsLabel setText:[NSString stringWithFormat:@"Tips for %@ and %@ to work together more effectively:",characterType1,characterType2]];
[compareText sizeToFit];
[vsLabel sizeToFit];
mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);
[scroller addSubview:mainView];
}
I just want to show some data on UILabel when the code run it shows like that.I just want show the data fit on to the Ui label regardless of the device. What I want to do is I just want to keep the font line steady and change the label size according to the no of line in the description
enter image description here
ios objective-c
ios objective-c
edited Nov 21 '18 at 21:06
asked Nov 20 '18 at 22:59
Kasun
11
11
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fitmainView
.. so I suspect the calculations are incorrect.
– Brandon
Nov 21 '18 at 1:13
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07
add a comment |
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fitmainView
.. so I suspect the calculations are incorrect.
– Brandon
Nov 21 '18 at 1:13
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fit
mainView
.. so I suspect the calculations are incorrect.– Brandon
Nov 21 '18 at 1:13
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fit
mainView
.. so I suspect the calculations are incorrect.– Brandon
Nov 21 '18 at 1:13
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07
add a comment |
1 Answer
1
active
oldest
votes
about " mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);"
do you init the mainView.frame first?
you can print the mainView.frame.origin and mainView.frame.size to make sure whether is inited
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402883%2fcontent-does-not-fit-on-to-the-ui-label%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
about " mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);"
do you init the mainView.frame first?
you can print the mainView.frame.origin and mainView.frame.size to make sure whether is inited
add a comment |
about " mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);"
do you init the mainView.frame first?
you can print the mainView.frame.origin and mainView.frame.size to make sure whether is inited
add a comment |
about " mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);"
do you init the mainView.frame first?
you can print the mainView.frame.origin and mainView.frame.size to make sure whether is inited
about " mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,padding*5 + lineH + labelH*3 + compareText.frame.size.height+imageViewH);"
do you init the mainView.frame first?
you can print the mainView.frame.origin and mainView.frame.size to make sure whether is inited
answered Nov 23 '18 at 3:17
liunianhuaguoyanxi
142
142
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402883%2fcontent-does-not-fit-on-to-the-ui-label%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
First of all.. why are you using Frames.. secondly, how did you measure the size of the label? Finally.. the frame of your label has a problem with its width and height. The size may be too large to fit
mainView
.. so I suspect the calculations are incorrect.– Brandon
Nov 21 '18 at 1:13
@Brandon I just put the whole code.Can you tell what did I miss
– Kasun
Nov 21 '18 at 21:07