当我触摸目标c中的标签时,如何根据标签的大小增加/减小矩形大小

时间:2017-04-17 10:01:19

标签: ios objective-c uiview uilabel

我有一个矩形和两个标签,如子视图类中的label1,label2。

  1. label1固定在矩形内部,或者你可以说矩形里面有label1。
  2. label2距离屏幕上的label1有一段时间,并且可以拖动,因为我在子视图中应用了触摸移动的方法并制作label2.userInteractionEnabled = YES
  3. 现在我想将label2与带触摸的label1连接起来,它工作正常,但矩形大小没有更新。
  4. 当我将label2与label1连接时,矩形大小也应更新为label1 + label2大小以适合其中的两个标签。我怎么能得到这些东西...... 这是我的代码。

    _targetRect = [[UIView alloc]init];
    self.frame = CGRectMake(10,70,70,30
    [self addsubView:_targetRect];
    

    对于Label一个相同的x,y位置作为targetRect

     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];
    

1 个答案:

答案 0 :(得分:1)

在label2框架设计之后重新设计矩形框架尺寸。等,

_targetRect.frame = CGRectMake(10,70, width, label1.frame,size.height+label2.frame,size.height)];
相关问题