1. 自定義ActionSheet背景
首先 #import <QuartzCore/QuartzCore.h>
然后實現UIActionSheetDelegate方法:
- (void)willPresentActionSheet:(UIActionSheet*)actionSheet { UIImage*theImage =[UIImage imageNamed:@"detail_menu_bg.png"]; theImage =[theImage stretchableImageWithLeftCapWidth:32 topCapHeight:32]; CGSize theSize = actionSheet.frame.size; // draw the background image and replace layer content UIGraphicsBeginImageContext(theSize); [theImage drawInRect:CGRectMake(0,0, theSize.width, theSize.height)]; theImage =UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [[actionSheet layer] setContents:(id)theImage.CGImage];} }
2.自定義ActionSheet按鈕背景圖片
網上找了很多方法, stackOverFlow上有在actionSheet 的subviews里找到ValueforKey:@"_button"類似的代碼,確實能實現更改背景圖片,但這觸碰到了apple的私有api,有可能進不了app store。同理,改UIThreePartButton的也不推薦。
最方便的方法是:http://code4app.com/ios/CMActionSheet/5024d0896803fa8056000000
這個第三方控件使用很方便,代碼也很清晰。button的點擊事件回調方法是block寫的,如果使用上有問題,可以修改一下源碼。
