Dou*_*ith 10 objective-c uiactionsheet ios ios7
我在整个应用程序中使用绿色作为"动作颜色",我希望我的UIActionSheets中的选项也是绿色的,以保持一致性.如何将UIActionSheet选项的颜色从蓝色更改为绿色?
Ste*_*vin 28
利用willPresentActionSheet
委托方法UIActionSheet
更改操作表按钮颜色.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
button.titleLabel.textColor = [UIColor greenColor];
}
}
}
Run Code Online (Sandbox Code Playgroud)
Mat*_*ang 18
你可以这样做:
// Your code to instantiate the UIActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
// Configure actionSheet
// Iterate through the sub views of the action sheet
for (id actionSheetSubview in actionSheet.subviews) {
// Change the font color if the sub view is a UIButton
if ([actionSheetSubview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)actionSheetSubview;
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
}
}
Run Code Online (Sandbox Code Playgroud)
如果您要重复使用它,我会将UIActionSheet子类化并使用此代码.
归档时间: |
|
查看次数: |
9032 次 |
最近记录: |