0

我的表格有一个自定义的部分标题。我添加了一个按钮
button1.frame = CGRectMake(frame.size.width-70, 5.0, 35.0, 35.0); 这会将按钮放在右上角。但是,当我自动旋转到横向时,按钮保持在与纵向模式相同的位置?我错过了什么?

-(id)initWithFrame:(CGRect)frame title:(NSString*)title section:(NSInteger)sectionNumber delegate:(id <SectionHeaderViewDelegate>)delegate AllAnswered:(SectionAnswered)sectionAnswered{

self = [super initWithFrame:frame];

if (self != nil) {

    // Set up the tap gesture recognizer.
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleOpen:)];

    tapGesture.cancelsTouchesInView = NO;

    [self addGestureRecognizer:tapGesture];

    _delegate = delegate;
    self.userInteractionEnabled = YES;


    //create applyAll image
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(frame.size.width-70, 5.0, 35.0, 35.0);
    button1.backgroundColor = [UIColor clearColor];
    button1.opaque = NO;
    button1.tag= 1;
    [button1 setImage:[UIImage imageNamed:@"carat-open.png"] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(applyToAll:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button1];
    _applyButton = button1;

     .............
     }
4

1 回答 1

0

您可以设置按钮的autoresizingMask.

button1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
于 2012-12-01T06:46:26.740 回答