2011年4月12日 星期二

修改UIActionSheet的Button風格

利用UIActionSheetDelegate的Callback Function就可以做到自定義風格


- (void)willPresentActionSheet:(UIActionSheet *)actionSheet  // before animation and showing view
{
    // 搜尋UIActionSheet中的Action Sheet Button View
    for (UIView* view in [actionSheet subviews])
    {
        if ([[[view class] description] isEqualToString:@"UIThreePartButton"])
        {
            if ([view respondsToSelector:@selector(title)])
            {
                // 修改位置
                NSString* title = [view performSelector:@selector(title)];
                if ([title isEqualToString:@"Button 1"] && [view respondsToSelector:@selector(setEnabled:)])
                {
                    [view performSelector:@selector(setEnabled:) withObject:NO];
                }
            }
        }
    }
}