Finished implementing appearance methods

This commit is contained in:
Warren Moore
2012-09-17 01:36:05 -05:00
parent 37fb05d160
commit bf1234f979
8 changed files with 99 additions and 26 deletions

View File

@@ -27,30 +27,24 @@
self.view.backgroundColor = [UIColor grayColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(85, 225, 143, 44);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"custom-cancel-normal"] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
button.frame = CGRectMake(85, 125, 143, 44);
button.autoresizingMask = UIViewAutoresizingFlexibleMargins;
[button setTitle:@"Show Alert View" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (IBAction)buttonWasPressed:(id)sender {
NSString *message = @"Doyouthinkhesawus. Lorem ipsum perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium explicabo.";
static NSInteger dismissalStyle = 1;
AHAlertView *alert = [[AHAlertView alloc] initWithTitle:@"What Do You Call a Blind Dinosaur?" message:message];
[alert setCancelButtonTitle:@"Cancel" block:^{
alert.dismissalStyle = dismissalStyle;
dismissalStyle = (dismissalStyle + 1) % 5;
}];
[alert addButtonWithTitle:@"OK" block:^{
alert.dismissalStyle = dismissalStyle;
dismissalStyle = (dismissalStyle + 1) % 5;
}];
[alert show];
UILabel *switchLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 225, 120, 16)];
switchLabel.text = @"Custom Styles";
switchLabel.font = [UIFont boldSystemFontOfSize:15];
switchLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:switchLabel];
UISwitch *appearanceSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(175, 217, 0, 0)];
[appearanceSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:appearanceSwitch];
}
- (void)viewDidAppear:(BOOL)animated
@@ -63,4 +57,57 @@
return YES;
}
- (IBAction)buttonWasPressed:(id)sender {
NSString *title = @"Alert View Title";
NSString *message = @"Here is a message informing you of something that happened. Do you want to do something about it?";
AHAlertView *alert = [[AHAlertView alloc] initWithTitle:title message:message];
[alert setCancelButtonTitle:@"Cancel" block:^{
alert.dismissalStyle = AHAlertViewDismissalStyleTumble;
}];
[alert addButtonWithTitle:@"OK" block:nil];
[alert show];
}
- (void)switchValueChanged:(UISwitch *)sender
{
if(sender.isOn)
[self applyCustomAlertAppearance];
else
[AHAlertView applySystemAlertAppearance];
}
- (void)applyCustomAlertAppearance
{
[[AHAlertView appearance] setContentInsets:UIEdgeInsetsMake(12, 18, 12, 18)];
[[AHAlertView appearance] setBackgroundImage:[UIImage imageNamed:@"custom-dialog-background"]];
[[AHAlertView appearance] setCancelButtonBackgroundImage:[UIImage imageNamed:@"custom-cancel-normal"]
forState:UIControlStateNormal];
[[AHAlertView appearance] setButtonBackgroundImage:[UIImage imageNamed:@"custom-button-normal"]
forState:UIControlStateNormal];
[[AHAlertView appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:18], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
nil]];
[[AHAlertView appearance] setMessageTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:14], UITextAttributeFont,
[UIColor colorWithWhite:0.8 alpha:1.0], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
nil]];
[[AHAlertView appearance] setButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:14], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(0, -1)], UITextAttributeTextShadowOffset,
nil]];
}
@end