我试图从是不从厦门国际银行加载自定义视图类的.m内做到这一点,而是编程:UIView的背景颜色的设置自
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor=[UIColor redcolor];
}
return self;
}
我有无论我把背景颜色放在initWithFrame还是其他方法中都是一样的结果。背景颜色属性不需要。从控制器,拥有该自定义视图,我可以设置背景色精,有:
self.mycustomview.backgroundColor=[UIColor redcolor];
但我想从自定义视图自身内做到这一点,保持这样的东西无关。控制器和自定义视图导入UIKit。
我也试过这个,这是可以从代码预见:
self.View.backgroundColor=[UIColor redcolor];
但这并不工作。我在这里尝试了view
和View
。我确定我忽略了一些非常明显的东西。
在视图控制器我有这个,它工作正常。自定义视图被称为“mapButtons.h”:
- (void)viewDidLoad
{
CGRect frame=CGRectMake(0, 0, 320, 460);
self.mapButtons=[[mapButtons alloc] initWithFrame:frame];
self.mapButtons.backgroundColor=[UIColor redColor];
[self.view addSubview:self.mapButtons];
自定义视图的.H是这样的:
#import <UIKit/UIKit.h>
@interface mapButtons : UIView
当我编译我得到这个错误“请求成员的backgroundColor东西不是一个结构或联合” – johnbakers