我使用循环制作3个标签现在我想制作一个带有3个标签x位置的矩形,我的意思是我的标签x位置完成的地方应该是矩形出现与矿工边界差异。当我单击视图时,只显示一个带有最后一个label3的矩形。我怎么能得到其他环形标签的矩形。
for(int i = 0; i<3; i++){
UILabel *label[UILabel alloc]init];
//whatever label frame and other properties
}
我制作一个矩形,在我的触摸开始方法我设置与标签框相关的矩形框...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CGSize maximumLabelSize = CGSizeMake(50,30);
CGSize expectedLabelSize = [_lbl.text sizeWithFont:_lbl.font
constrainedToSize:maximumLabelSize
lineBreakMode:_lbl.lineBreakMode];
CGRect newFrame = self.lbl.frame;
newFrame.size.width = expectedLabelSize.width;
self.lbl.frame = newFrame;
CGRect newFrame1 = rectangle.frame;
newFrame1.size.width = expectedLabelSize.width;
newFrame1.origin.x = self.lbl.frame.origin.x + self.lbl.frame.size.width;
rectangle.frame = newFrame1;
答案 0 :(得分:0)
考虑使用stackView
e.g。 //堆栈视图
UIStackView *stackView = [[UIStackView alloc] init];
stackView.axis = UILayoutConstraintAxisHorizontal;
stackView.distribution = UIStackViewDistributionEqualSpacing;
stackView.alignment = UIStackViewAlignmentCenter;
stackView.spacing = 10;
//然后在你的循环中
[stackView addArrangedSubview: label];