이 문제는 며칠 동안 당황 스럽습니다.프로그래밍 방식으로 생성 된 UIButton을 숨길 수 없습니다.
두 개의 UIButton이 있습니다. 하나는 스토리 보드를 사용하여 만들고 다른 하나는 프로그래밍 방식으로 만듭니다.
단추 중 하나를 누르면 프로그래밍 방식으로 작성된 단추와 스토리 보드 단추가 모두 숨겨 지지만 스토리 보드 단추 만 사라지는 반면 프로그래밍 방식으로 작성된 단추는 남아 있습니다. 숨기기뿐만 아니라 프로그래밍 방식으로 작성된 버튼의 프레임을 변경하려고 시도했지만 아무 소용이 없습니다. 여기 코드가 사용됩니다
@property (strong, nonatomic) UIButton *catBut;
@property (weak, nonatomic) IBOutlet UIButton *whenButton;
....
....
-(void)viewDidLoad {
....
[self customizeButton:self.catBut withFrame:CGRectMake(165, 113, 135, 50)
andAction:@selector(selectedCat) andColor:[UIColor belizeHoleColor]
andTag:2 andImage:@"coffee-64.png" andText:@"Cafes" andAlignmentLeft:YES];
....
}
- (void)customizeButton:(UIButton *)but withFrame:(CGRect)rect andAction:(SEL)action
andColor:(UIColor *)col andTag:(NSUInteger)tag
andImage:(NSString *)imageName
andText:(NSString *)buttonText
andAlignmentLeft:(BOOL)alignLeft {
but = [UIButton buttonWithType:UIButtonTypeCustom];
[but setFrame:rect];
[but setTitle:buttonText forState:UIControlStateNormal];
but.tag = tag;
but.titleLabel.numberOfLines = 0;
but.titleLabel.font = [UIFont boldFlatFontOfSize:18];
[but setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
CGFloat spacing = 10; // the amount of spacing to appear between image and title
but.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
but.imageEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
but.titleEdgeInsets = UIEdgeInsetsMake(0, spacing*2, 0, 0);
[but setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[but setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
[but addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
[self.buttonsView addSubview:but];
}
....
- (void)selectedCat {
self.catBut.hidden = YES;
self.whenButton.hidden = YES;
}
왜 UI 변경 만 스토리 보드 버튼을 준수? 제가 누락 된 것이 있습니까? 나는 AutoLayout을 취소하려했지만 그 일은 변하지 않았다.
당신이 문제를 해결했습니다! 정말 고마워. – Yarneo
나는 그것이 UIButton 포인터의 전달과 관련이 있다는 점에 직감이있었습니다. – Yarneo
문제가 해결되었습니다. – nanjunda