Reputation: 170
I'm trying to change the color of the button in my UIActionSheet
. The problem (a really weird problem) is that if the orientation of the device is Landscape the button color doesn't change!
Some screenshot:
I can't figure out why!
Here's the code:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
[actionSheet.subviews enumerateObjectsUsingBlock:^(id _currentView, NSUInteger idx, BOOL *stop) {
if ([_currentView isKindOfClass:[UIButton class]]) {
[((UIButton *)_currentView).titleLabel setTextColor:[[MSAppDelegate sharedInstance] defaultColor]];
}
}];
/*
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[[MSAppDelegate sharedInstance] defaultColor] forState:UIControlStateNormal];
[button setTitleColor:[[MSAppDelegate sharedInstance] defaultColor] forState:UIControlStateSelected];
}
if ([subview isKindOfClass:[UILabel class]]) {
UILabel *label = (UILabel *)subview;
label.textColor = [[MSAppDelegate sharedInstance] defaultColor];
}
}
*/
}
I also tried the commented code, both work in Portrait but not in Landscape!
By the way either in Landscape and in Portrait the code is executed!
If you want to see all the code here's the link
Thank you in advance!
Upvotes: 0
Views: 1384
Reputation: 2525
use this method to set button title color then i am sure your problem will solve
[[[actionSheet valueForKey:@"_buttons"] objectAtIndex:0] setTitleColor:[[MSAppDelegate sharedInstance] defaultColor] forState:UIControlStateNormal];
Upvotes: 1
Reputation: 4406
You could Subclass the UIActionSheet
class and implement the tableView:willDisplayCell:forRowAtIndexPath:
selector:
@interface MSActionSheet : UIActionSheet
@end
@implementation MSActionSheet
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[[cell subviews] enumerateObjectsUsingBlock:^(id v, NSUInteger idx, BOOL *stop) {
[[v subviews] enumerateObjectsUsingBlock:^(id v2, NSUInteger idx, BOOL *stop) {
if ([v2 isKindOfClass:[UILabel class]]) {
[(UILabel *)v2 setTextColor:[[MSAppDelegate sharedInstance] defaultColor]];
}
}];
}];
}
@end
Upvotes: 4