2013-09-27 66 views
0

我在我的应用程序中使用了SBTableAlert库,但在iOS 7中,此库不起作用。 我修复了它,增加了TSAlertView,对话框显示正常。 但我的问题是,按钮的位置不是它应该的。在SBTableAlert中设置按钮位置

我设置按钮的位置:

-(void)willPresentTableAlert:(SBTableAlert *)tableAlert{ 
    int counter = 0; 
    for (id view_sub in self.filterAlert.view.subviews) { 
     if ([view_sub isKindOfClass:[UIButton class]]) { 
      switch (counter) { 
       case 0: 
        ((UIButton*)view_sub).frame = CGRectMake(10, 
                 10, 
                 144, 
                 44); 
        ((UIButton*)view_sub).backgroundColor = [UIColor redColor]; 
        break; 
       case 1: 
        ((UIButton*)view_sub).frame = CGRectMake(169, 
                    150, 
                    144, 
                    44); 
        break; 
       case 2: 
        ((UIButton*)view_sub).frame = CGRectMake(328, 
                    150, 
                    144, 
                    44); 
        break; 

       default: 
        break; 
      } 
      counter++; 
     } 
    } 
} 

的事情是,按钮被涂成红色,但帧组一行忽略,而不是内层,它们被放在一个下的其他进出警报框架。

回答

0

我终于找到了答案。 问题出在TSAlertVeiw库中,因为它具有函数recalcSizeAndLayout:布局,它在末尾调用并覆盖按钮的自定义位置。

的解决方案是在TSAlertView customLayoutOfButton添加新BOOL变量,然后自动布局之前检查你的按钮:

if (!self.customLayoutOfButton) { 
     CGFloat buttonHeight = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero].height; 
     if (stacked) 
     { 
      CGFloat buttonWidth = maxWidth; 
      for (UIButton* b in self.buttons) 
      { 
       b.frame = CGRectMake(kTSAlertView_LeftMargin, y, buttonWidth, buttonHeight); 
       y += buttonHeight + kTSAlertView_RowMargin; 
      } 

     } 
     else 
     { 
      CGFloat buttonWidth = (maxWidth - kTSAlertView_ColumnMargin)/2.0; 
      CGFloat x = kTSAlertView_LeftMargin; 
      for (UIButton* b in self.buttons) 
      { 
       b.frame = CGRectMake(x, y, buttonWidth, buttonHeight); 
       x += buttonWidth + kTSAlertView_ColumnMargin; 
      } 
     } 
}