This is a requirement in the project. to display an overview of a book, two rows are displayed by default. Click the expand button to show all, and click reclaim. Two rows are displayed.
At the beginning, a code like this may be written in the button event:
If (isExpand ){
[LblBrief setNumberOfLines: 2];
LblBrief. text = [StringUtil subString: strBrief AndSubLength: 90];
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefDown"] forState: UIControlStateNormal];
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefDown"] forState: UIControlStateHighlighted];
} Else {
[LblBrief setNumberOfLines: 0];
LblBrief. text = strBrief;
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefUp"] forState: UIControlStateNormal];
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefUp"] forState: UIControlStateHighlighted];
}
You can use setNumberOfLines: 0 to display the summary content. However, if you do not calculate the total height of all content to be displayed, the width and height of the label will not automatically increase.
Else {
[LblBrief setNumberOfLines: 0];
LblBrief. text = strBrief;
CGSize constraint = CGSizeMake (self. view. frame. size. width-(15*2), 20000.0f );
CGSize size = [strBrief sizeWithFont: [UIFont systemFontOfSize: 10] constrainedToSize: constraint lineBreakMode: UILineBreakModeWordWrap];
[Brief setFrame: CGRectMake (15,160, size. width, size. height)];
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefUp"] forState: UIControlStateNormal];
[BtnBrief setImage: [UIImage imageNamed: @ "detailBriefUp"] forState: UIControlStateHighlighted];
}