我想我ViewController
使用這種方法變化子UIView的背景顏色
- (void)viewDidLoad
{
[super viewDidLoad];
addCourse = [[UIView alloc]init];
addCourse.backgroundColor = [UIColor redColor];
[addCourse.layer setCornerRadius:50.0f];
[addCourse.layer setMasksToBounds:YES];
}
哪裏addCourse
是我的subview
但背景顏色是白色還是在添加子視圖。我正在使用storyboard
並添加了subview
並將該視圖與viewcontroller
關聯,我確實編寫了IBOutlet和屬性並進行了合成,但仍無法找到更改背景顏色的方法。
我該如何改變它?
如何在ViewController中添加addCourse? – 2013-03-07 04:37:40
1.您沒有設置框架2.您沒有將子視圖添加到主視圖!那麼你將如何得到它? – 2013-03-07 04:53:13
設置框架並將子視圖添加到self.view。 addCourse.frame = CGRectMake(10.0,10.0,200.0,200.0); [self.view addSubview:addCourse]; – Cintu 2013-03-07 06:14:07