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];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM