Question

I was using SBTableAlert library in my app, but with iOS 7 this library won't work. I fix it whit adding TSAlertView and dialogs are showing fine. But my problem is that position of button is not as it should be.

I set position of the button in :

-(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++;
        }
    }
}

The thing is that button is painted red but frame set is ignored, instead of lining in one line, they are put one under the other and out of the Alert frame.

Was it helpful?

Solution

I finally found the answer. The problem was in TSAlertVeiw library, because it has function recalcSizeAndLayout:layout which is called at the end and overwrite your custom position of the buttons.

The solution was to add new BOOL variable in TSAlertView customLayoutOfButton and then check it before auto layout your buttons:

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;
            }
        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top