我的桌子有一个自定义的Section Header。我给它添加了一个按钮
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 :(得分:0)
您可以设置按钮的autoresizingMask
。
button1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;