{
CGFloat frameWidth = self.frame.size.width;
CGFloat tagsTotalWidth = 20.0f;
CGFloat tagsTotalHeight = 16.0f;
CGFloat tagHeight = 0.0f;
for (Datamodel *Data in dataAry ){
tagHeight = tagBtn.frame.size.height;
tagsTotalWidth += tagBtn.frame.size.width + 8.0f;
// 自动换行
if (tagsTotalWidth >= frameWidth){
tagsTotalHeight += tagBtn.frame.size.height + 10.0f;
tagsTotalWidth = 20.0f;
tagBtn.frame = CGRectMake(tagsTotalWidth, tagsTotalHeight, tagBtn.frame.size.width, tagBtn.frame.size.height);
tagsTotalWidth += tagBtn.frame.size.width + 8.0f;
}
[self addSubview:tagBtn];
tagIndex++;
}
tagsTotalHeight += tagHeight;
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, frameWidth, tagsTotalHeight + 8.0f * 2);