UIAlertView をカスタマイズするための優れた機能があります。2 つのボタンで完璧に機能しますが、問題は、2 つのボタンではなく 1 つのボタンしかないことをどのように知ることができるかということです。または、ボタンが 1 つしかない問題のある配置をどのように解決しますか?
私のコードは次のとおりです。
- (void)layoutSubviews
{
for (id obj in self.subviews) //Search in all sub views
{
if ([obj isKindOfClass:[UIImageView class]])
{
UIImageView *imageView = (UIImageView*)obj;
float width = 284.0;
float height = 141.0;
CGSize size = CGSizeZero;
size.width = width;
size.height = height;
UIImage *newImage = [self imageWithImage:[UIImage imageNamed:@"CustomAlertView"] scaledToSize:size];
imageView.image = newImage;
[imageView sizeToFit];
}
if ([obj isKindOfClass:[UILabel class]]) // Override UILabel (Title, Text)
{
UILabel *label = (UILabel*)obj;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor clearColor];
label.font = [UIFont fontWithName:kFONT_NAME size:kFONT_SIZE];
}
if ([obj isKindOfClass:[UIButton class]]) // Override the UIButton
{
UIButton *button = (UIButton*)obj;
CGRect buttonFrame = button.frame; // Change UIButton size
buttonFrame.size = CGSizeMake(127, 35);
CGFloat newYPos = buttonFrame.origin.y + 9; // Change UIButton position
buttonFrame.origin.y = newYPos;
button.frame = buttonFrame;
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
switch (button.tag)
{
case kFIRST_BUTTON:
{
[button setBackgroundImage:[UIImage imageNamed:@"short_orange_button_off"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"short_orange_button_on"] forState:UIControlStateHighlighted];
}
break;
case kSECOND_BUTTON:
{
[button setBackgroundImage:[UIImage imageNamed:@"short_button_black_off"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"short_button_black_on"] forState:UIControlStateHighlighted];
}
break;
}
}
}
[self updateConstraints];
}