(見最後一段)。
但是兩天前,作者發現在“Indentity Inspector”導航欄下,有一個很可疑的參數——“Custom Class”它的下面還有一個更可疑的參數“User Defined Runtime Attributes”見下圖
既然Apple給出了“Custom Class”,那麼就意味了我們可以用自己定製的類,我是我就實驗了一下,結果,果斷成功!下面就給大家介紹具體的步驟:
1、首先要建立一個類:MyImgView繼承UIButton
#import <Foundation/Foundation.h>
@interface MyImgView : UIButton
//對外接口
@property NSNumber *cornerRadius;
@end
MyImgView.m 內容:
#import "MyImgView.h"
#import <QuartzCore/CALayer.h>
@implementation MyImgView
@synthesize cornerRadius;
- (void)drawRect:(CGRect)rect
{
// Drawing code
[[self layer] setCornerRadius:[cornerRadius floatValue]];
[[self layer] setMasksToBounds:YES];
NSLog(@"111111");
}
@end
2、將一個button控件拖入xib,設置一張按鈕圖片,如下圖:
3、設置此按鈕的“Custom Class”和“User Defined Runtime Attributes”,如下圖:
4、Run it!
本文適合懶人一族,如有紕漏,請多指正!