Has anyone been able to find a way to set the text alignment of the UIAlertController
. More specifically, the action sheet style?
I am using this method to add pictures (icons) to the actions :
UIImage *qsimage = [UIImage imageNamed:@"snapshot.png"];
[snapshot setValue:qsimage forKey:@"image"];
//where 'snapshot' is a UIAlertAction
This works just fine, no worries, but when adding multiple actions to the controller all the text is centered but the images are left aligned creating an awkward UI experience.
I'm trying to resemble what Apple has done in the soon to be iOS 8.4 for their Music app:
Thoughts? Am I missing something simple?
edit
After doing some debugging I've realized the Alert Actions are in a UICollectionView. I can successfully change the colors of all the buttons, but can't alter the labels of the actions in terms of alignment. Here is how I accessed them:
[[UICollectionView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor blueColor]];
I also tried using setTitleTextAttributes on the actions with NSDictionary objects and keys with no success. Any ideas?
This is tested and working - UILabel+Appearance.h:
@interface UILabel (FontAppearance)
@property (nonatomic, assign) NSTextAlignment appearanceAlignment UI_APPEARANCE_SELECTOR;
@end
@implementation UILabel (FontAppearance)
-(void)setAppearanceAlignment:(NSTextAlignment)alignment {
[self setTextAlignment:alignment];
}
-(NSTextAlignment)appearanceAlignment {
return self.textAlignment;
}
@end
Usage:
UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:UIAlertController.class, nil];
[appearanceLabel setAppearanceAlignment:NSTextAlignmentLeft];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With