2012-12-01 120 views
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; 

    ............. 
    } 

回答

0

您可以設置按鈕的autoresizingMask

button1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin; 
相關問題