Home > Mobile >  IOS development lable adaptive padding after how to solve
IOS development lable adaptive padding after how to solve

Time:12-01

Lable with [lb44 text boundingRectWithSize: CGSizeMake (* KB5HEIGHT kWindowW - 20, 1000) options: NSStringDrawingUsesLineFragmentOrigin attributes: [NSDictionary dictionaryWithObjectsAndKeys: lb44. The font, NSFontAttributeName, nil] context: nil]; Methods

Under the great god told me

CodePudding user response:

Do you have a highly adapt yourself? I will not
STR + (CGSize) caluteStr: (nsstrings *) Si (CGSize) Si fon (CGFloat) the font {
Return [STR boundingRectWithSize: si options: NSStringDrawingUsesLineFragmentOrigin attributes: @ {NSFontAttributeName: [UIFont systemFontOfSize: the font]} the context: nil]. Size;
}

CodePudding user response:

I am using this method, and then after calculating the height to make the lable fame change, but found that lable have padding up and down, and content is the more the number of rows in the lable, padding, the greater the eldest brother know what's the problem?

CodePudding user response:

reference 1st floor qq_35996263 response:
highly adapt themselves to do you have? I will not
STR + (CGSize) caluteStr: (nsstrings *) Si (CGSize) Si fon (CGFloat) the font {
Return [STR boundingRectWithSize: si options: NSStringDrawingUsesLineFragmentOrigin attributes: @ {NSFontAttributeName: [UIFont systemFontOfSize: the font]} the context: nil]. Size;
}
I am using this method, and then after calculating the height to make the lable fame change, but found that lable have padding up and down, and content is the more the number of rows in the lable, padding, the greater the eldest brother know what's the problem?

CodePudding user response:

Then add [lb44 sizeToFit];

CodePudding user response:

Should be you are used to calculate the width and the actual set to the width of the label is not consistent

CodePudding user response:

NSStringDrawingOptions opts=NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
Init NSMutableParagraphStyle * style=[[NSMutableParagraphStyle alloc]].
[style setLineBreakMode: NSLineBreakByCharWrapping];
NSDictionary * attributes=@ {NSFontAttributeName: [UIFont systemFontOfSize: 18], NSParagraphStyleAttributeName: style};
CGRect the rect=[string boundingRectWithSize: CGSizeMake (width, MAXFLOAT) options: opts attributes: attributes the context: nil];
LineBreakMode attribute and the font size should be consistent, fixed width width
  •  Tags:  
  • iOS
  • Related