![](/img/trans.png)
[英]iOS - Interface Builder - bind multiple view inside the same xib
[英]IOS use inherited View inside interface builder
我擴展了UIImageView以便創建更圓的圖像視圖:
#import <QuartzCore/QuartzCore.h>
#import "RoundedImageView.h"
@implementation RoundedImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self makeImageViewRounded];
}
return self;
}
-(void) makeImageViewRounded {
self.layer.backgroundColor=[[UIColor clearColor] CGColor];
self.layer.cornerRadius=20;
self.layer.borderWidth=1.0;
self.layer.masksToBounds = YES;
self.layer.borderColor=[[UIColor whiteColor] CGColor];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
在故事板上,我已經將UIImageView連接到我的自定義RoundedImageView,但是它似乎並沒有影響視圖,也沒有調用我的代碼。
我如何使每當我將自定義視圖附加到UIView時,都會初始化該自定義視圖?
從情節提要板創建視圖時,請重寫此初始化程序:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
if (self) {
[self makeImageViewRounded];
}
return self;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.