2017-09-29 8 views
-7

誰かが以下のようなプログラムで男性と女性の性別の徴候をiOSに描く方法を知っていますか?iOSで男性と女性の性別記号を描く

Gender symbols

+1

このトピックでは、彼または彼女は、正確な問題は、これらの図面を作るにあるものへと述べるいないのと閉じる必要があります。さらに、それらの図面を作ることは、実際にプログラミングの質問ではありません。 –

+1

CoreGraphicsを見ることができます。 – azamsharp

+2

'UILabel'で女性と男性の文字を使い、System 200' '♀' '' "♂" 'のような大きなフォントを使います。 – vacawama

答えて

9

女性のシンボルを描画する例を示します。 まず、それを描画するUIBezierPathを使用して、レイヤを行います。その後

import UIKit 

class FemaleLayer: CAShapeLayer { 

    override var frame: CGRect { 
     didSet{ 
      self.draw() 
     } 
    } 

    private func draw() { 
     self.lineWidth = 20.0 
     self.fillColor = UIColor.clear.cgColor 
     self.strokeColor = UIColor.black.cgColor 

     let path = UIBezierPath() 
     let sideLength = fmin(self.frame.width, self.frame.height) 
     let circlesRadius = (sideLength/2.0 - self.lineWidth) * 0.6 
     let circleCenterY = self.bounds.midY * 0.8 

     path.addArc(withCenter: CGPoint(x:self.bounds.midX, y:circleCenterY), radius: circlesRadius, startAngle: 0.0, endAngle: 2 * CGFloat.pi, clockwise: true) 

     let circleBottomY = circleCenterY + circlesRadius 
     path.move(to: CGPoint(x: self.bounds.midX, y: circleBottomY)) 
     path.addLine(to: CGPoint(x: self.bounds.midX, y: circleBottomY + circlesRadius)) 
     path.move(to: CGPoint(x: self.bounds.midX * 0.6, y: circleBottomY + circlesRadius * 0.5)) 
     path.addLine(to: CGPoint(x: self.bounds.midX * 1.4, y: circleBottomY + circlesRadius * 0.5)) 

     self.path = path.cgPath 
    } 
} 

はUIViewのにレイヤーを追加することによって、それを使用する:

let femaleLayer = FemaleLayer() 
femaleLayer.frame = self.view.bounds 
self.view.layer.addSublayer(femaleLayer) 

最終結果:
enter image description here

は、男性用:

class MaleLayer: CAShapeLayer { 
    override var frame: CGRect { 
     didSet{ 
      self.draw() 
     } 
    } 

    private func draw() { 
     self.lineWidth = 20.0 
     self.fillColor = UIColor.clear.cgColor 
     self.strokeColor = UIColor.black.cgColor 

     let path = UIBezierPath() 
     let sideLength = fmin(self.frame.width, self.frame.height) 
     let circlesRadius = (sideLength/2.0 - self.lineWidth) * 0.6 
     let circleCenterX = self.bounds.midX * 0.9 
     let circleCenterY = self.bounds.midY * 1.2 

     path.addArc(withCenter: CGPoint(x:circleCenterX, y:circleCenterY), radius: circlesRadius, startAngle: 0.0, endAngle: 2 * CGFloat.pi, clockwise: true) 

     let circleRightTopX = circleCenterX + circlesRadius * 0.686 
     let circleRightTopY = circleCenterY - circlesRadius * 0.686 
     let lineLength = circlesRadius * 0.7 
     path.move(to: CGPoint(x: circleRightTopX, y: circleRightTopY)) 
     path.addLine(to: CGPoint(x: circleRightTopX + lineLength, y: circleRightTopY - lineLength)) 
     path.move(to: CGPoint(x: circleRightTopX, y: circleRightTopY - lineLength)) 
     path.addLine(to: CGPoint(x: circleRightTopX + lineLength + self.lineWidth/2.0, y: circleRightTopY - lineLength)) 
     path.move(to: CGPoint(x: circleRightTopX + lineLength, y: circleRightTopY - lineLength)) 
     path.addLine(to: CGPoint(x: circleRightTopX + lineLength , y: circleRightTopY)) 

     self.path = path.cgPath 
    } 
} 

enter image description here

+0

ちょっとマイナーな(?)もの...あなたが提供したコードはおそらく 'FemaleLayer'という名前にしてください:-) –

+0

ハハハ、ばかな間違い!それを示してくれてありがとう!回答が更新されました。 –

関連する問題