- (void)addUnderLine
{
/**
* 取出第一个button,初始化下划线
*/
NSArray *topicScrollViewSubArr = self.topicBarCollectionView.subviews;
UIButton *topicBtn = nil;
for (id subview in topicScrollViewSubArr)
{
if ([subview isKindOfClass:[UIButton class]])
{
topicBtn = subview;
break;
}
}
UIView *underlineView = [[UIView alloc] init];
[self.topicBarView addSubview:underlineView];
underlineView.backgroundColor = [topicBtn titleColorForState:UIControlStateSelected];
[topicBtn.titleLabel sizeToFit]; // 让label根据文字内容计算尺寸--- 需要在设置frame之前
underlineView.KL_height = KL_UnderlineH;
underlineView.KL_width = topicBtn.titleLabel.KL_width;
underlineView.KL_y = self.topicBarCollectionView.KL_height;
underlineView.KL_centerX = topicBtn.KL_centerX;
}
获取button文字的大小
最新推荐文章于 2023-08-17 10:28:54 发布