2017-01-04 5 views
0

私は私のUIViewコンテナでベジエパスデザインを完成させようとしていますが、サンプルアプリケーションが添付されているほど大きなサイズになるようにパスのサイズを正しく取得するようです。これは私が作ったベジェのパスですが、そのサイズは小さすぎ、塗りつぶしの色(ベジェパス)は白く塗るのではなく、むしろ黒です。ベジエパスの重複デザイン

enter image description here

これは私も内部のUIImageViewを配置するために複製する波平サンプル画像です。

enter image description here

これは私のコンテナに何を行っていること、私ははるかにこれを持って私のコードです:

import UIKit 

class ProfileViewControllerNew: UIViewController/*, UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout*/{ 

    // Properties 
    var topContainer : UIScrollView = UIScrollView() 
    var profileImage : UIImageView = UIImageView() 
    var settingIcon : UIImageView = UIImageView() 
    var shareIcon : UIImageView = UIImageView() 
    var sessionScrollView : UIScrollView = UIScrollView() 
    var scrollViewContainer : UICollectionView = { 
     let layout = UICollectionViewFlowLayout() 
     let cV = UICollectionView(frame: .zero, collectionViewLayout: layout) 
     return cV 
    }() 
    var firstname : String! 
    var location: UILabel! 
    let layer = CAShapeLayer() 
// triangle view 
    var triangleView : UIView = UIView() 


    override func viewDidLoad() { 
     super.viewDidLoad() 
//  setStatusBarBackgroundColor(color : UIColor.init(red: 49/255, green: 207/255, blue: 203/255, alpha: 1)) 
     self.view.backgroundColor = UIColor.init(red: 49/255, green: 207/255, blue: 203/255, alpha: 1) 

     self.navigationController?.navigationBar.isHidden = false 
     self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) 
     self.navigationController?.navigationBar.shadowImage = UIImage() 
     self.navigationController?.navigationBar.isTranslucent = true 
     self.navigationController?.navigationBar.barStyle = UIBarStyle.default; 
     self.view.backgroundColor = UIColor.white 

     addContaier() 
     trView() 
//  scrollViewSetup() 
//  titleTextView() 
//  imageView() 
//  textViews() 
//  iconsView() 
//   

    } 

    func addContaier(){ 
     // adding container to add image 
     self.topContainer.backgroundColor = UIColor(red: 49/255, green: 207/255, blue: 203/255, alpha: 1) 
     //  self.topContainer.backgroundColor = UIColor.white 
     self.topContainer.translatesAutoresizingMaskIntoConstraints = false 
     view.addSubview(self.topContainer) 

     let myImage : UIImage = UIImage(named : "profile.jpeg")! 
     let imageView : UIImageView = UIImageView() 
     imageView.image = myImage 
     imageView.frame = self.topContainer.bounds 
     //imageView.contentMode = UIViewContentMode.scaleAspectFill 

     //  self.topContainer.addSubview(imageView) 
     self.topContainer.topAnchor.constraint(equalTo: view.topAnchor, constant : 0).isActive = true 
     self.topContainer.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 
     //self.topContainer.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true 
     self.topContainer.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.55).isActive = true 
     self.topContainer.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true 



     /* 
     layer.path = UIBezierPath(roundedRect: CGRect(x: profileImage.frame.origin.x, y:profileImage.frame.origin.y , width: 30, height: 30), cornerRadius: 30).cgPath 
     layer.fillColor = UIColor.red.cgColor 

     self.topContainer.layer.addSublayer(layer) 
     self.layer.addSublayer(<#T##layer: CALayer##CALayer#>) 
     */ 

    } 

    func trView(){ 


    let bezierPath = UIBezierPath() 

     bezierPath.move(to : CGPoint(x:0,y: 462)) 
     bezierPath.addCurve(to :CGPoint(x:414,y: 226), controlPoint1: CGPoint(x:414.5,y: 230), controlPoint2: CGPoint(x:414.5,y: 226)) 
     bezierPath.addLine(to: CGPoint(x:414,y: 462)) 
     bezierPath.addLine(to: CGPoint(x:0,y: 462)) 
     UIColor.white.setFill() 
     bezierPath.fill() 
     bezierPath.lineWidth = 1 
//  bezierPath.stroke() 
//  bezierPath.close() 
     //   path.lineCapStyle = kCGLineCapSquare 
     let line = CAShapeLayer() 
     line.path = bezierPath.cgPath; 

//  line.strokeColor = UIColor.black.cgColor 
//  line.fillColor = UIColor.white.cgColor 
     self.topContainer.layer.addSublayer(line) 

} 
} 

はそれらにUIImageViewsを追加するために、同じ三角形の景色を私を助けることができる誰もが複製されています?

ありがとうございます!

+0

私はベジェ曲線は見えません。直線のみです。 –

+0

私は形状の塗りつぶしを行うことができるようにベジェパスで行くことをお勧めしました。たとえそれが直線であったとしても、ラインの下の形を塗りつぶすのはどうすればいいですか?(私はあなたを正しく理解していますか?) – Aboogie

+0

正直言っていいでしょう。私の専門知識は、iosの開発ではなく、ベジェ曲線です。なぜ私は、直線のクリッピングのためにベジエ - 何かが必要なのか、簡単にはわかりませんでした。 –

答えて

0

これは必要なものですか?これは、線を斜めに描き、底部がパスになるように原点に接続します。

func initialSetup() { 
    self.view.backgroundColor = UIColor.cyan 
    let path = UIBezierPath() 
    path.move(to: CGPoint(x: 0, y: self.view.center.y + 40)) 
    path.addLine(to: CGPoint(x: self.view.frame.size.width, y: self.view.center.y - 40)) 
    path.addLine(to: CGPoint(x: self.view.frame.size.width, y: self.view.frame.size.height)) 
    path.addLine(to: CGPoint(x: 0, y: self.view.frame.size.height)) 
    path.close() 

    self.view.drawPolygon(path: path.cgPath) 
} 

func drawPolygon(path: CGPath) { 
    let shapeLayer = CAShapeLayer() 
    shapeLayer.path = path 
    shapeLayer.lineWidth = 2.0 
    shapeLayer.strokeColor = UIColor.white.cgColor 
    shapeLayer.fillColor = UIColor.white.cgColor 
    self.layer.addSublayer(shapeLayer) 
}