iOS 設置View投影 需要設置 顏色 陰影半徑 等元素 ...
iOS 設置View投影
需要設置 顏色 陰影半徑 等元素
UIView *shadowView = [[UIView alloc] init]; shadowView.frame = CGRectMake(100, 100, 100, 100); shadowView.center = self.view.center; shadowView.backgroundColor = [UIColor whiteColor]; //設置陰影顏色 shadowView.layer.shadowColor = [UIColor colorWithRed:114.0/255.0 green:133.0/255.0 blue:152.0/255.0 alpha:1.0].CGColor; //設置陰影的透明度 shadowView.layer.shadowOpacity = 0.1f; //設置陰影的偏移 shadowView.layer.shadowOffset = CGSizeMake(30.0f, 10.0f); //設置陰影半徑 shadowView.layer.shadowRadius = 15.0f; //設置渲染內容被緩存 shadowView.layer.shouldRasterize = YES; //超出父視圖部分是否顯示 shadowView.layer.masksToBounds = NO; shadowView.layer.borderWidth = 0.0; shadowView.layer.opaque = 0.10; shadowView.layer.cornerRadius = 3.0; //柵格化處理 shadowView.layer.rasterizationScale = [[UIScreen mainScreen]scale]; //正常矩形 UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowView.bounds]; shadowView.layer.shadowPath = path.CGPath; [self.view addSubview:shadowView];