【发布时间】:2015-03-26 03:01:25
【问题描述】:
我在 Storyboard 中创建了两个 UIView。现在,我正在尝试为两者设置渐变背景:
-(void)drawView
{
// Set the Views Background Color
[self.depMetarView setBackgroundColor:[UIColor clearColor]];
[self.destMetarView setBackgroundColor:[UIColor clearColor]];
// Draw a custom gradient
CAGradientLayer *depMetarGradient = [IGABackgroundLayer gradientBlue];
CAGradientLayer *destMetarGradient = [IGABackgroundLayer gradientBlue];
depMetarGradient.frame = self.depMetarView.bounds;
destMetarGradient.frame = self.destMetarView.bounds;
[self.depMetarView.layer insertSublayer:depMetarGradient atIndex:0];
[self.destMetarView.layer insertSublayer:destMetarGradient atIndex:0];
// Round button corners
[self.depMetarView.layer setMasksToBounds:YES];
[self.depMetarView.layer setCornerRadius:5.0];
[self.destMetarView.layer setMasksToBounds:YES];
[self.destMetarView.layer setCornerRadius:5.0];
// Apply a 1 pixel, black border
[self.depMetarView.layer setBorderWidth:1.0f];
[self.depMetarView.layer setBorderColor:[[UIColor blueColor] CGColor]];
[self.destMetarView.layer setBorderWidth:1.0f];
[self.destMetarView.layer setBorderColor:[[UIColor blueColor] CGColor]];
}
现在,这就是我得到的:
我知道视图的边界有问题。试过这个:
CGRect depViewBounds = CGRectMake(self.depMetarView.frame.origin.x,self.depMetarView.frame.origin.y,self.depMetarView.frame.size.width, self.depMetarView.frame.size.height);
[self.depMetarView setBounds:depViewBounds];
...但无济于事。
谁能帮忙?
谢谢!
【问题讨论】:
标签: objective-c uiview background gradient