【问题标题】:Custom UIViews For Collage App拼贴应用的自定义 UIViews
【发布时间】:2018-07-06 00:32:22
【问题描述】:

我正在开发一个拼贴应用程序,我已经成功构建了简单的拼贴,但现在我被困在如何构建复杂风格的拼贴上,如下图所示

我将如何创建图像中的自定义视图,我尝试使用 Beizerpath 并通过使用 beizerpath 的路径对视图应用蒙版,但是当我无法向图层添加阴影时将蒙版应用于视图。任何帮助,将不胜感激。如何在图像中准确创建带有阴影的视图类型?

【问题讨论】:

    标签: ios iphone swift uiview calayer


    【解决方案1】:

    要求某人确切地告诉您如何实现您的应用的功能不适合本网站。

    使用 CAShapeLayers 并设置它们的各种阴影属性,如 shadowOpacity、shadowRadius、shadowOffset、shadowColor 和 shadowPath。

    【讨论】:

      【解决方案2】:

      使用此代码

         import UIKit
      
      class ViewController: UIViewController {
      
          @IBOutlet var image1: UIImageView!  // your image outlet
          override func viewDidLoad() {
      
      
      super.viewDidLoad()
              // Do any additional setup after loading the view, typically from a nib.
          }
      
          override func viewDidAppear(_ animated: Bool) {
      
      
      
                let trianglePath = UIBezierPath()
              trianglePath.move(to: CGPoint(x: 0, y: image1.frame.size.height - 60))
              trianglePath.addLine(to: CGPoint(x:0, y: image1.frame.size.height))
              trianglePath.addLine(to: CGPoint(x: image1.frame.size.width, y: image1.frame.size.height))
              trianglePath.close()
              let path = UIBezierPath(rect: view.bounds)
      
              path.append(trianglePath)
      
      
              let maskLayer = CAShapeLayer()
              maskLayer.frame = image1.bounds
      
              maskLayer.fillRule = kCAFillRuleEvenOdd
      
              maskLayer.path = path.cgPath
      
              image1.layer.mask = maskLayer
      
      
      
          }
      
          override func didReceiveMemoryWarning() {
              super.didReceiveMemoryWarning()
              // Dispose of any resources that can be recreated.
          }
      
      
      }
      

      还有更多形状link appcoda

      【讨论】:

        猜你喜欢
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-02
        • 2014-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多