我现在已经用了很长一段时间了。由于我没有真正找到解决方案,我希望有人能够帮助我。
我有一个UIActionSheet,我希望有不同的背景颜色。 随着
[[myAlert layer] setBackgroundColor:[UIColor redColor].CGColor];
我能够改变大部分警报的颜色。 这就是它的样子:
这是我初始化UIActionSheet的方法:
UIActionSheet *styleAlert = [[UIActionSheet alloc] initWithTitle:AMLocalizedString(@"SELECT_PICTURE_TITLE", @"Überschrift des Actionsheets")
delegate:self
cancelButtonTitle:AMLocalizedString(@"CANCEL_BUTTON_TITLE", @"Abbrechen butten")
destructiveButtonTitle:nil
otherButtonTitles:AMLocalizedString(@"TAKE_PICTURE_BUTTON_TITLE", @"Bild aufnehmen button"),
AMLocalizedString(@"CAMERA_ROLL_BUTTON_TITLE", @"Aus Bibliothek auswählen"), nil];
// use the same style as the nav bar
[styleAlert showInView:self.parentViewController.tabBarController.view];
//[styleAlert showInView:[self.navigationController view] ];
[styleAlert release];
和
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
actionSheet.layer.backgroundColor = GLOBAL_TINT_COLOR.CGColor;
}
我无法弄清楚如何用相同的颜色设置边框。有什么想法吗?
提前致谢!
答案 0 :(得分:1)
您无法以不同的颜色重绘边框,因此只需删除边框并添加自己的边框:
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet {
UIView *contentView = actionSheet.superview;
UIView *popoverView = contentView.superview;
UIView *chromeView;
for (UIView *v in [popoverView subviews]) {
if (v.subviews.count == 3) {
chromeView = v;
break;
}
}
for (UIView *backgroundComponentView in [chromeView subviews]) {
backgroundComponentView.hidden = YES;
CGRect componentFrame = backgroundComponentView.frame; // add your view with this frame
}
}
请注意,这不会在* will * PresentActionSheet中有效,因为actionSheet
此时没有设置superview
。
答案 1 :(得分:0)
这适用于iPhone主题,它也可能适用于iPad。
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed@""]];
imageView.frame = CGRectMake(0, 0, actionSheet.frame.size.width, actionSheet.frame.size.height);
[actionSheet insertSubview:imageView atIndex:0];
NSArray *subviews = [actionSheet subviews];
for (UIView *v in subviews) {
if ([v isKindOfClass:[UIButton class]]) {
//Theme the buttons on the action sheet
UIButton *b = (UIButton *)v;
}
else if ([v isKindOfClass:[UILabel class]]) {
UILabel *l = (UILabel *)v;
//Theme the label at the top of the action sheet
}
}
}