IOS--UIView 視覺效果:圓角、陰影、邊框、漸變光澤
首先新增框架 QuartzCore.framework
在檔案中引入 #import <QuartzCore/QuartzCore.h>
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(20, 100,280, 300)];
myView.backgroundColor = [
//圓角
myView.layer.cornerRadius = 6; // 圓角的弧度
myView.layer.masksToBounds = YES;
//陰影
myView.layer.shadowColor = [[UIColorredColor] CGColor];
myView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f); //[水平偏移, 垂直偏移]
myView.layer.shadowOpacity = 1.0f; // 0.0 ~ 1.0 的值
myView.layer
//邊框
myView.layer.borderWidth = 2;
myView.layer.borderColor = [[UIColorblackColor] CGColor];
//漸變光澤
CAGradientLayer *gradient = [CAGradientLayerlayer];
gradient.frame = myView.bounds;
gradient.colors = [NSArrayarrayWithObjects:(id)[[UIColorwhiteColor]
[myView.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:myView];
[myView release];
}