我有以下代码来绘制自定义选择器。不幸的是,首次绘制的视图是黑色的。只有当我触摸它时才会出现。
我该如何解决这个问题?
以下是UIView中的相关代码:
- (void)drawRect:(CGRect)rect
{
[self createPicker];
[self addSubview:dPicker];
//[dPicker reloadComponent:1];
}
-(void) createPicker
{
dPicker = [[UIPickerView alloc] initWithFrame:CGRectZero];
CGSize pickerSize = [dPicker sizeThatFits:CGSizeZero];
dPicker.frame = [self pickerFrameWithSize:pickerSize];
dPicker.delegate=self;
dPicker.showsSelectionIndicator = YES;
dPicker.hidden=NO;
}
- (CGRect)pickerFrameWithSize:(CGSize)size
{
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGRect pickerRect = CGRectMake( 0.0,
screenRect.size.height - 44.0 - size.height,
size.width,
size.height);
return pickerRect;
}
答案 0 :(得分:0)
修正了它。从UIViewController而不是UIView
调用子视图