由有關
這裏看到的圖片是剛剛創建的動態幀的UILabel
方法看看這個 通過獲得對UIlabel
高度和寬度可以計算整個高度,可以設置這樣的描述標籤上顯示UITableView.
- (void)setLabeltextWithVerticalAlignTop:(NSString *)theText
{
CGSize labelSize;
// here labelSize is hard-wired but could use constants to populate the size
labelSize = CGSizeMake(210, 129);//this is just for example
//now create the Size from textString SO that We could assign this size to the Label.
CGSize theStringSize = [theText sizeWithFont:lblTitle.font constrainedToSize:labelSize lineBreakMode:lblTitle.lineBreakMode];
lblTitle.frame = CGRectMake(lblTitle.frame.origin.x, lblTitle.frame.origin.y, theStringSize.width, theStringSize.height);
lblTitle.text = theText;
}
呼叫上述方法的行高設置,您需要通過文字描述標籤的高度和寬度。 當您獲得該標籤的高度時,現在基於此您可以調整TableView的高度。
編輯:上面的代碼就創建動態幀爲的UILabel
You should take a view of this這是你在尋找什麼......!在這裏,你會發現一個示例代碼太。
編輯:當你編輯你的問題看,它只是你需要將它轉換成可運行代碼的邏輯它在這裏。
在代碼中使用下面的方法調用每一行,並在其中進行一些計算。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat rowHeight=0.0;
//here it seems cell have 4 subview added on it.
//so if you could calculate the totla hieht of them.
//so what you really need to do.you just use hieght calculative Method for getting hieght of each of three UILabel
//you need to modify `setLabeltextWithVerticalAlignTop` method .
rowHeight= [self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];// suppose it returns some hieght for FisrtLabel.
//suppoose here you get the 20.0 height here
rowHeight= rowHeight+[self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];
//假設它爲secondUIlabel返回一些高度。
//suppoose here you get the 40.0 height here
rowHeight= rowHeight+ [self setLabeltextWithVerticalAlignTop:@"pass the correspondingText"];
// suppose it returns some hieght for ThirdUIlabel.
// suppoose here you get the 15.0 height here
//here you have totla height you just need to add some gapping floating value for all of three UIlabel.so that the could not overlap like as.
rowHeight= rowHeight+20.0;
//now you can return that total height
return rowHeight;
}
注:這只是你需要把它轉換成可運行code.i相信這能幫助邏輯。
我希望它可以幫助你。
你有沒有試過這個鏈接,在我的答案中提到.. !!! – Kamarshad