我在 subview 类中有一个矩形和两个标签,如 label1、label2。
- label1 固定在矩形内部,或者您可以说矩形内部有 label1。
- label2 在屏幕上距离 label1 有一段时间,它是可拖动的,因为我在我的 subview 中应用了 touches moved 方法并使
label2.userInteractionEnabled = YES
- 现在我想通过触摸连接 label2 和 label1,它工作正常,但矩形大小没有更新。
当我将 label2 与 label1 连接时,矩形大小也应更新为 label1+label2 大小以适合其中的两个标签。我如何获得这些东西... 这是我的代码。
_targetRect = [[UIView alloc]init]; self.frame = CGRectMake(10,70,70,30 [self addsubView:_targetRect];
对于与targetRect相同的x,y位置的Label
label1 = [[UILabel alloc]init]; self.frame = CGRectMake(10,70, width, hight)]; [self addsubView: label1];
对于 label2 x, y 位置远离标签 1
label2 = [[UILabel2 alloc]init]; self.frame = CGRectMake(100,70, width, hight)]; label2.userInteractionEnabled = YES; [self addsubView:label2];
最佳答案
在label2框架设计后重新设计了矩形框大小。喜欢,
_targetRect.frame = CGRectMake(10,70, width, label1.frame,size.height+label2.frame,size.height)];
关于ios - 当我触摸 objective-c 中的标签时,如何根据标签的大小增加/减少矩形大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43449269/